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 Professional Discussion / Random number generation

Author
Message
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 23rd Mar 2010 15:45
If I put a specific seed in the random number generation, the next time I do a rnd(100) will I get the same number on every computer each time that is done?

The fastest code is the code never written.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 23rd Mar 2010 16:17
Yes.

TheComet

Mnemonix
23
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: Skaro
Posted: 23rd Mar 2010 16:18
I'm not sure if this is true. Isn't it a hardware thing that can vary between machines?

Your signature has been erased by a mod because it's larger than 600x120
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 23rd Mar 2010 16:19
I know that DBC acts like that. So it should be the same with DBP?

TheComet

Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 23rd Mar 2010 16:32
If it's software, then it should be the same. If it's hardware/OS then it may not be. That's what I need to know.

The fastest code is the code never written.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Mar 2010 23:14
Have you even tried doing it?

Why wait for over 6 hours for an answer you can provide yourself in under 30 seconds?

Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 23rd Mar 2010 23:29
I could try it on my computer, but how will I know if I get the same random sequence on other computers???? The question was not how to or what does; it's about "how does" DPB do random numbers? Does it use it's own formula or does it use something that windows generates or does it use something that may be in hardware??? Using MY computer will give me no answers.....

The fastest code is the code never written.
Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 23rd Mar 2010 23:40 Edited at: 23rd Mar 2010 23:44
I believe it's done totally within the program, so it doesn't matter what computer you're using it on. It's more useful like this.

If you're unconvinced, run this:



You should get



Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 23rd Mar 2010 23:51
Thanks. When I get to my pc, I'll try it..... BTW what OS are you using? That's another variable I am unsure of. I have Win7.

The fastest code is the code never written.
Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 23rd Mar 2010 23:59 Edited at: 23rd Mar 2010 23:59
XP

If it depends on anything it'll be the version of darkbasic, but i don't think they've changed the random number generation code. Once it's compiled into an exe for distribution it won't matter.

That's in the event there is a difference. I would be very surprised if there was.

Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 24th Mar 2010 00:14
Quote: "Once it's compiled into an exe for distribution it won't matter."

I think that too, but I wanted to be sure since my game would depend on that.

The fastest code is the code never written.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Mar 2010 00:27 Edited at: 24th Mar 2010 00:34
This isn't an idle question to ask. A few years ago we established on one of our threads that certain floating point calculations were processor dependent. I forget the details so can't easily locate the discussion. Something to do with Intel versus the rest. It might have been a bug report.

So, if such things can happen it's quite possible that rnd() will give different results on different processors. If DBPRO is using full precision integer arithmetic with the rnd() function then such problems shouldn't arise.

It should only take 30 seconds for IanM to tell us.

Edit Here's the arithmetic bug I was referring to:

certain calculations processor dependent

I've no idea what the current position is.
Duke E
17
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 24th Mar 2010 03:03
You could write your own random generator.
This example uses a simple LCG (Linear Congruential Generator) with Park & Miller range values, cheer old speccy =).



Regards
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 24th Mar 2010 04:05
I've been looking for that kind of generator. Thanks. It didn't give an even distribution, but I modified it and now it seems to do the trick.


The fastest code is the code never written.

Login to post a reply

Server time is: 2026-07-26 23:40:37
Your offset time is: 2026-07-26 23:40:37