DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Pascal and Delphi (http://www.daniweb.com/forums/forum124.html)
-   -   Trying to find a better way to generate random numbers in Dev Pascal (http://www.daniweb.com/forums/thread26257.html)

Shadowhawk Jun 21st, 2005 9:11 am
Trying to find a better way to generate random numbers in Dev Pascal
 
Hello to everyone who sees this post!

I am not very experienced in programming, but I have some basic knowledge, and the first real programming language I happen to learn is Dev Pascal. I have compiled a program which generates random numbers, using the RANDOM(); function. It is actually a dice roller.

The thing is, that every time I run the program, I get the same sequence of numbers. For example, if I run the program and get 4, 2, 1, 6, the next time I run the program, I will get again 4, 2, 1, 6!

I have searched the Web and found out that this problem is due to the mathematical expression the RANDOM(); function uses, and this makes it "generate" the same numbers every time it runs again, as the "seed", the initial value of the number it uses, is the same. But those ARE NOT random numbers!

If there is anyone who can help me find a better way to generate REALLY random numbers, please, do so! I don't know if there is the possibility to get clock values in Dev Pascal, and if there is, how to use it... Any help will be appreciated. PLEASE HELP ME!!! PLEASE!!! :sad:

Jackrabbit Jun 21st, 2005 2:23 pm
Re: Trying to find a better way to generate random numbers in Dev Pascal
 
http://lazarus-ccr.sourceforge.net/d...em/random.html

Shadowhawk Jun 22nd, 2005 7:57 am
Re: Trying to find a better way to generate random numbers in Dev Pascal
 
Thank you, Jackrabbit! It really worked!
The error was the missing Randomize; in the beginning. I had the same seed every time, thus getting the same sequence of numbers! Thanks again!
Actually, I found the answer myself, just a few minutes after I posted that... in another website... But the thought and only is worth it! thank you!


All times are GMT -4. The time now is 8:15 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC