Skip to content

Instantly share code, notes, and snippets.

@DreamVB
Created June 25, 2021 09:50
Show Gist options
  • Save DreamVB/c2696853821ee4ab9b950737eca04dc2 to your computer and use it in GitHub Desktop.
Save DreamVB/c2696853821ee4ab9b950737eca04dc2 to your computer and use it in GitHub Desktop.
UK lotto number generator
//UK lotto generator
#include <iostream>
#include <vector>
#include <time.h>
#include <algorithm>
using namespace std;
int main(){
int x = 0;
int lotto_lines = 6;
int max_balls = 59;
int how_many_balls = 6;
std::vector<int>balls;
//Get randome seed
std::srand(unsigned(time(0)));
//Init UK lotto number range 1 to 59 for UK
while (x < max_balls){
//INC x
x++;
//Push number onto balls vector
balls.push_back(x);
}
std::cout << "-------------------------------" << std::endl;
std::cout << "UK Lucky Numbers for the Lottery" << std::endl;
std::cout << "--------------------------------" << std::endl;
for (int t = 1; t < lotto_lines; t++){
//Shuffle vector
std::random_shuffle(balls.begin(), balls.end());
for (int x = 0; x < how_many_balls; x++){
//Align the number or if number is less than 10
if (balls[x] < 10){
std::cout <<" " << balls[x] << " ";
}
else{
std::cout << balls[x] << " ";
}
}
std::cout << std::endl;
}
std::cout << "--------------------------------" << std::endl;
std::cout << "Hope you win this week :)" << std::endl;
std::cout << "--------------------------------" << std::endl;
//Clear vector
balls.clear();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment