C++ random integers

I could use some help with a c++ program that has to display six unique random integers for a lottery game. the random integers have to from 1 through 54. I don't know how to make it pick random integers. please help!
1
2
3
4
5
6
7
8
#include <iostream>
#include <cstdlib>
#include <ctime>

int main(){
    srand(time(0)); //Seeds the PRNG. Call only once per program.
    std::cout <<rand()<<std::endl; //0 <= rand() <= RAND_MAX
}
Last edited on
thanks you! but how do you program it for 6 random numbers from 1 through 54?
closed account (D80DSL3A)
rand()%54 + 1 will give #s from 1 to 54.
You may have to generate more than 6 numbers from this before you get 6 unique ones (no repeated values).
I am having a lot of trouble with this class. how do i get it to generate the 6 random numbers. I understand the 1 to 54 but it only shows one number when i run the program
How about a loop?
Topic archived. No new replies allowed.