hi, This is a small lotto generator I made it simple it makes 59 numbers stores them into a array and then suffle the array and then I pick the first 6 numbers. There is more than likey a better way of doing this. But it seems to work. Hope you like it comments welcome.
Code:// File : lotto.c // By : Ben a.k.a DreamVB // Date : 17/06/2020 // Info : A small UK lotto number generator. #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <ctype.h> #include <time.h> #define MAX_BALLS 59 #define WIN_BALLS 6 void shuffle_array(int arr[], int size) { int t = 0; //Get random seed srand(time(NULL)); int i = size - 1; while(i > 0) { const int j = rand() % (i + 1); //Swap items in array t = arr[j]; arr[j] = arr[i]; arr[i] = t; //DEC i i--; } } int main() { int balls[MAX_BALLS] = {0}; int x = 0; //Load balls for(int x = 0; x<MAX_BALLS; x++){ balls[x] = x+1; } //Shuffle the 59 balls shuffle_array(balls,MAX_BALLS); //Display lotto banner puts("+------------------------+"); puts("| UK Lotto Winning Balls |"); puts("+------------------------+"); x = 0; //Print out the first 6 winning balls while(x < WIN_BALLS){ printf("%d ",balls[x]); x++; } puts("\n--------------------------"); return 0; }




Reply With Quote
