Hi im writing a program to simulate a slot machine, where a user enteres a coin and has a 70% chance of winning (say 3 coins). Anyways, I have a class slotMachine with a public int random() function.
Here is the function:
int slotMachine::random()
{
srand( time(NULL));
randomNum = rand() % 7 + 1; // from 1 to 7
return randomNum;
}
The function should generate a number between 1 and 7, if the user enters a number between this they win.
However, when I run the program and test to see what number the function prints it always prints 5. Is this because srand(time(NULL)) generates a long value, and when I try to convert it to an integer it only prints the first number of the geterated long type value? How can I fix this?