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.

DarkBASIC Discussion / Random Numbers

Author
Message
BadMonkey91
21
Years of Service
User Offline
Joined: 13th Jan 2004
Location:
Posted: 3rd Jun 2004 22:40 Edited at: 3rd Jun 2004 22:54
This is wierd, but when I use the rnd() command to generate random numbers, it works fine within the DBC editing tool.

But if I build an executable file, it does not work properly.

It generates "Random" numbers, but in a sequential order, resulting in the same numbers being generated every time the program is opened.

Is there a patch, or some help? Has anyone every encountered this before?

[edit]I looked through some other threads, and found someone saying something like seeding your random numbers, can you do that in DB?

Oibaf2000
21
Years of Service
User Offline
Joined: 31st Jan 2004
Location:
Posted: 3rd Jun 2004 23:09
From a post I had startedDreamKeeper's response)


So if you want a REAL random you have to use this:





You must use randomize timer() because you will seed the Random generator with "Timer()" and because Timer() never is the same, you will get REAL random . Then you must throw away the first 100 random's because they aren't really random.

Hope this helps
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 3rd Jun 2004 23:13
First 100 aren't random? What are you talking about? Rnd() can never be truely random, even if you use randomize timer(), timer() is a regular and eventually repeating pattern, therefore if you run your program twice, at the same processor time, you will get the same results. As for the first 100 being not random, I've never heard that one before .

Athelon XP 1600+/Radeon 9600 Pro/256 RAM
BadMonkey91
21
Years of Service
User Offline
Joined: 13th Jan 2004
Location:
Posted: 3rd Jun 2004 23:18
yeah, I thought I'd have to create a timer within my program.
Sort of a pain in the @$$.

BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Jun 2004 15:04
Throwing away the first 100 does nothing.

Randomize picks a seed. That is, a starting point. It then continues sequentially again. Missing 100 acheives nothing more than adding 100 to your original seed.

To generate a more random sequence, you need to use randomize several times in your program, preferably at unpredictable points.

BatVink
http://facepaint.me.uk/catalog/default.php AMD 3000+ Barton, 512Mb Ram, 120 Gig Drive space, GeForce 5200 FX 128 Mb, Asus A7N8X Mobo.
Terms & Conditions apply
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 4th Jun 2004 16:43
BadMonkey - Create a timer? The timer() command is already there for you. It returns the processor time in milliseconds. Just stick the line RANDOMIZE TIMER() at the top of your program.

Athelon XP 1600+/Radeon 9600 Pro/256 RAM
Powersoft
21
Years of Service
User Offline
Joined: 1st Aug 2003
Location: United Kingdom
Posted: 6th Jun 2004 13:32
get the time and use that

Im not a rubbish programmer...Everyone else is just better than me....
If we were supposed to sing we would look like Kylie...
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 6th Jun 2004 17:47
Just add a load of random things (FPS / mousex() etc.) together.

Login to post a reply

Server time is: 2025-05-23 22:46:12
Your offset time is: 2025-05-23 22:46:12