#19914 - darknet - Wed Apr 28, 2004 12:01 am
Well one of the mini-games I am working on goes like so:
Its basically a classical video gaming quiz (since my project is a collection of classic remakes) that shows the user a screenshot of some famous game that they have to name by selecting from the choices given. I have 25 built in as of now but only require the user to look at 10 and get 10 correct.
The entire mini-game seems very trivial to me with the exception of one aspect. I want the sequence of screens to be random and not have the same one appear twice.
For example, I want to prevent the folowing sequence: Mortal Kombat II, Dig Dug, Mario Kart, Mortal Kombat II.
To fight that right now, I have a screenshot structure that has a 'used' flag that is set when the screenshot has been randomly generated.
However, the only routine I can think of for generating a random screen is as follows:
Ideally, I want a function that gets a random number bounded by the amount of screens available, and once a number has been generated, DO NOT use that same generated value again when the random function is recalled within a loop.
Sorry if this seems trivial, I know what I have will work, but I want to somehow prevent from constantly generating the same random number, thus slowing down the program dramatically.
Any help is greatly appreciated,
-Mike
Its basically a classical video gaming quiz (since my project is a collection of classic remakes) that shows the user a screenshot of some famous game that they have to name by selecting from the choices given. I have 25 built in as of now but only require the user to look at 10 and get 10 correct.
The entire mini-game seems very trivial to me with the exception of one aspect. I want the sequence of screens to be random and not have the same one appear twice.
For example, I want to prevent the folowing sequence: Mortal Kombat II, Dig Dug, Mario Kart, Mortal Kombat II.
To fight that right now, I have a screenshot structure that has a 'used' flag that is set when the screenshot has been randomly generated.
However, the only routine I can think of for generating a random screen is as follows:
Code: |
//num_screens is the total amount available. Screenshot screens[num_screens]; ..... while(lessThanTenCorrect) { int screenToShow = (rand()%(num_screens-1)); if( !screens[screenToShow].used) { //go ahead and process and getinput and whatnot, set to used. } else { //pick another random number? } //check if ten have been answered....set lessThanTen to false if true } |
Ideally, I want a function that gets a random number bounded by the amount of screens available, and once a number has been generated, DO NOT use that same generated value again when the random function is recalled within a loop.
Sorry if this seems trivial, I know what I have will work, but I want to somehow prevent from constantly generating the same random number, thus slowing down the program dramatically.
Any help is greatly appreciated,
-Mike