-
May 6th, 2006, 10:19 PM
#1
Same random number every time?
Hi,
I have a program for selecting and playing music. One function is a random function to line up 10 random songs from the database. Thing is every time I run the program it generates the same series of random numbers. My code starts by getting the number of songs from the database. So it can generate the random number between 1 and the total number of songs.
Code:
Rand = Int((Num_Songs * Rnd) + 1)
At the moment Num_Songs = 5133 and when I generate the 10 random numbers I get 3622, 2739, 2975, 1487, 1550, 3977, 72, 3905, 4181, 3640 every time. So every time I start the program and press random I get the same 10 songs queue up. What am I doing wrong?
-
May 6th, 2006, 10:35 PM
#2
Re: Same random number every time?
You are missing one small yet major thing.
Code:
Randomize
Rand = Int((Num_Songs * Rnd) + 1)
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
May 7th, 2006, 12:12 AM
#3
Re: Same random number every time?
-
May 7th, 2006, 12:40 AM
#4
Re: Same random number every time?
Originally Posted by Taipan
Doh .. thanks
You're welcome. Don't fret it, we all forget little "random" things.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
May 7th, 2006, 11:48 AM
#5
Re: Same random number every time?
Make sure that you use RANDOMIZE at least once in your program, or you app will pick the same sequence each time you start the app.
-
May 7th, 2006, 12:05 PM
#6
Re: Same random number every time?
Originally Posted by dglienna
Make sure that you use RANDOMIZE at least once in your program, or you app will pick the same sequence each time you start the app.
Even better is to use RANDOMIZE only once in your program. For this application is would't really matter, but RANDOMIZE re-seeds the random number generator using a non-random value. So, as counter-intuitive as it seems, the more times you call RANDOMIZE the less randomly distributed the numbers will be.
BTW,
Originally Posted by peejavery
I heard that if you play the Windows CD backwards, you'll hear satanic messages.
But the most frightening thing is, if you play it forward, it installs Windows!
LOL
Last edited by Comintern; May 7th, 2006 at 12:08 PM.
Reason: Poor word choice.
-
May 7th, 2006, 02:02 PM
#7
Re: Same random number every time?
Originally Posted by Comintern
LOL
Yes, I am a Mac user.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|