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 number genorator that doesn't repeat any numbers!!!

Author
Message
The CodeSmith
21
Years of Service
User Offline
Joined: 28th Nov 2003
Location:
Posted: 20th Dec 2004 05:20
How do I make a random number genorator that counts from 1 to 25 without repeating any number? The code I have included gives me 25 random numbers, but they do repeat themselves.
Thanks

Intel P4 3.0 GHZ, 512 Duel RAM, Geforce 5200 Fx 128 MB, 80 GB Hard Drive
"May flying hamsters of DOOM rain coconuts on your city!"
Zedane
20
Years of Service
User Offline
Joined: 3rd Nov 2004
Location: Milky Way, Earth
Posted: 20th Dec 2004 09:40
you could do this the long way as in run the random number gen
rnd(25)+ 1 (1 to 25) and save the number in an array then do it again and if it matches any of the numbers in the array then have it not store that number but instead do it again untill it is a number that is not stored in the array

http://img96.exs.cx/img96/2382/sasa.gif
around here.. normal's just a setting on a hair dryer
ToXic
22
Years of Service
User Offline
Joined: 8th Sep 2002
Location: Australia
Posted: 20th Dec 2004 11:41 Edited at: 20th Dec 2004 11:41
Try this, example.





ToXic.
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 22nd Dec 2004 06:25
or do something like this

dim a(25)
for i=1 to 25
a(i)=i
print a(i)
next i
print
print
randomize timer()
for i=1 to 100
random1=int(rnd(24))+1
random2=int(rnd(24))+1
temp=a(random1)
a(random1)=a(random2)
a(random2)=temp
next i
for i=1 to 25
print a(i)
next i
wait key

all it does it start off with numbers 1 to 25 and then it shuffles them by picking two array locations at random and swapping the contents over, so your orderly list of numbers get shuffled, faster for large quantitys of numbers than checking for matches each pass, hope thats some help.

Mentor.

PC1: P4 3ghz, 1gig mem, 3x160gig hd`s, Radeon 9800pro w cooler (3rd gfx card), 6 way speakers.
PC2: AMD 2ghz, 512mb ram, FX5200 ultra, 16 bit SB.
Mini ATX cases suck.
BadMonkey91
21
Years of Service
User Offline
Joined: 13th Jan 2004
Location:
Posted: 22nd Dec 2004 20:31 Edited at: 22nd Dec 2004 20:38


maybe that

BigDan256
21
Years of Service
User Offline
Joined: 29th Oct 2003
Location: NSW, Australia
Posted: 22nd Dec 2004 21:30 Edited at: 22nd Dec 2004 22:09
This one should always run the same amount of time, think it's O(n^2/2)
The seq() array will be the resulting order of numbers


Or if you'd like more control over the length of time it takes to generate, and use less memory, this one should be O(n), where n is chosen by yourself


Edit: I just noticed Mentor had already suggested this last one

Here's a nice game of pickup 52

Login to post a reply

Server time is: 2025-05-27 21:00:36
Your offset time is: 2025-05-27 21:00:36