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
TrueDB
18
Years of Service
User Offline
Joined: 13th Nov 2007
Location:
Posted: 5th Dec 2007 01:48
Whats the best way to generate a random number? randamize and rnd are ok if you can find an external source of variable, Ive done it with the mouse position , anyone got a snippet to do a random number call thats RANDOM!(not repeated)

MAIN PROGRAM http://www.thewargamer.com/grognard/avalompro.zip GAME MODULES http://www.thewargamer.com/grognard/avittybitty.zip http://www.thewargamer.com/grognard/avalamo.zip
tha_rami
20
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 5th Dec 2007 03:32
Maybe try something insane, like "randomize rnd(timer()+mousex()+mousey())"


A mod has been erased by your signature because it was larger than 600x120
TrueDB
18
Years of Service
User Offline
Joined: 13th Nov 2007
Location:
Posted: 5th Dec 2007 04:05
Thanks tha_rami that was the command I wanted! so so glad I asked now.

MAIN PROGRAM http://www.thewargamer.com/grognard/avalompro.zip GAME MODULES http://www.thewargamer.com/grognard/avittybitty.zip http://www.thewargamer.com/grognard/avalamo.zip
Bluestar4
20
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 5th Dec 2007 07:49 Edited at: 5th Dec 2007 07:50
@tha_rami
its not insane but actually a good idea -
calling randomize before rnd will get you good results, and calling it like the code below will be quick,clean and very effective.

doing this will ensure that each time rnd is called that it will yeild a different number.
After calling randomize you can generate random numbers using the rnd call. example :



Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th Dec 2007 09:22
yes use RANDOMIZE TIMER(), doing that uses the internal clock to alter the random number generator, so it will make your program use a different random number calculation every time you run it.

I thought I was a genius when I thought that one up, but other people on here have been doing it for ages lol

"You must be someone's friend to make comments about them." - MySpace lied.
TrueDB
18
Years of Service
User Offline
Joined: 13th Nov 2007
Location:
Posted: 6th Dec 2007 11:02
hi OBese87

it was what I was looking for great, I found that unless you get an external random factor the random numbers repeated every time I started the program, I used MouseXY this was a useable method but could repeat when the button location was small, anyway all is well now with timer()

MAIN PROGRAM http://www.thewargamer.com/grognard/avalompro.zip GAME MODULES http://www.thewargamer.com/grognard/avittybitty.zip http://www.thewargamer.com/grognard/avalamo.zip
Bluestar4
20
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 7th Dec 2007 07:00
yes, if you call rnd without calling randomize first or provide the same number to randomize then the program will generate the same number every time its ran hence, the reason for using timer() to provide the random seed. You can use the mousex& y positions , but returning a variable from the timer() will ultimately prove to provide the most dynamic results.

TrueDB
18
Years of Service
User Offline
Joined: 13th Nov 2007
Location:
Posted: 7th Dec 2007 07:22
thanks Bluestar4 for your help! timer() is great

MAIN PROGRAM http://www.thewargamer.com/grognard/avalompro.zip GAME MODULES http://www.thewargamer.com/grognard/avittybitty.zip http://www.thewargamer.com/grognard/avalamo.zip
tha_rami
20
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 7th Dec 2007 12:09
go act absurd and use randomize ( timer()*timer() ).


A mod has been erased by your signature because it was larger than 600x120
TrueDB
18
Years of Service
User Offline
Joined: 13th Nov 2007
Location:
Posted: 7th Dec 2007 17:40
yeh good fun! heehe

MAIN PROGRAM http://www.thewargamer.com/grognard/avalompro.zip GAME MODULES http://www.thewargamer.com/grognard/avittybitty.zip http://www.thewargamer.com/grognard/avalamo.zip
TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 8th Dec 2007 02:10
Quote: "I thought I was a genius when I thought that one up, but other people on here have been doing it for ages"


Yes - only for about thirty years!

TDK_Man

Login to post a reply

Server time is: 2026-07-06 17:11:46
Your offset time is: 2026-07-06 17:11:46