'Random' Question
| BlahBlah (7) | |||
| Hi, I am wondering if you can ,after making a random number, take away that number from the random generator so you won't get it again the next time you make a random number. I am using srand. For example: x=rand()%10+1 //say for example this makes x = 3 when I do this again I want it to not make another 3. Thank you in advance! | |||
| Zaita (1562) | |||
| Not in the way you are thinking. But lets say you wanted to draw a lottery, numbers 1-10. Each number can only appear once. You'd do.
Haven't tested, or compiled that code. So take is as pseudo-code. Thats the theory of how I'd do it. Edit: Whoa. It worked first time lol. Scary | |||
| BlahBlah (7) | |||
| It worked! Thank you, Zaita! This also taught me what vectors were and how to use them. | |||
| Zaita (1562) | |||
| No worries :) Vectors are good to know, just good C++ STL if you wanna learn them better. | |||
| BlahBlah (7) | |||
| Yeah, I was trying to do it with an array (which I eventually got it to work) ,but using vectors was so much easier. | |||
This topic is archived - New replies not allowed.
