Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Random Number Generator that doesn't repeat the numbers.

Author
Message
Los29
14
Years of Service
User Offline
Joined: 14th Jun 2010
Location:
Posted: 15th Jun 2010 00:40
Hello Everyone,

I am fairly new at this. This program basically is just a program that changes the color of the screen. Right now the program runs well but when the numbers repeat from the random number generator my screen has a delay of an extra half a second.

I have been trying to figure out how to set a variable in order to capture the random number and then put it into and if () else () statement. There are only four possible outcomes 0 - 3 in the RNG.




If was thinking once I was able to get the variable set to captured the if() else() statement would look like this.



any help would be appreciated. Thank you.

Carlos
Kaichiro
14
Years of Service
User Offline
Joined: 19th Mar 2010
Location:
Posted: 15th Jun 2010 01:51 Edited at: 15th Jun 2010 01:53
Look up the command dbRandomize() in the documentation. Use the system clock to seed so you'll always have a different seed since the time is never the same twice.

including ctime will give you access to the time() function that will return the time from the system clock. Use that to seed and it should fix your problem.

Something like this (Not tested, shouldn't compile without more headers and whatnot...)

Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 15th Jun 2010 02:03
Well, I made this little command line program that will get the nubmers 0-3 for you in an order that is random and if a number has already been picked, the program will try again to find another number.



http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 15th Jun 2010 02:55
Or you could look here to see how they did it...

This is also a very popular question lately...

JTK
Los29
14
Years of Service
User Offline
Joined: 14th Jun 2010
Location:
Posted: 15th Jun 2010 03:26
thank you guys i have been on this for the last 2 days trying to make it work.

Carlos
Mnemonix
21
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: Skaro
Posted: 15th Jun 2010 12:38
I don't see why so many people attempt the "pick and then check against all others" for this problem. What you are essentially doing is shuffling a list of numbers, so there is no need for this to be so much of a hit on the cpu.

My solution is to take the following steps.

1. Fill your array with numbers sequentially, i.e. 1, 2, 3, 4, 5.
2. Loop once through the array and swap the value at each index with the value at a random index in the array. This ensures that no value is repeated.

Your signature has been erased by a mod because it's larger than 600x120

Login to post a reply

Server time is: 2024-11-19 23:12:14
Your offset time is: 2024-11-19 23:12:14