|
random()
#424023
06/09/13 20:02
06/09/13 20:02
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Hi again, the following code seems to only play the second song on every start of the game (the Story of Light one). I have started the game like twenty times, and each time it only plays the second the song. Am I doing something wrong with the code? Or is William Orbit lucky? This is the only code where I use media_loop in the game and I run it in the main function.
music_number = integer(random(2.99));
if (music_number == 0) media_loop("Café Del Mar Digby Jones Pina Colada (Jazz Mix).-.3astUpRoaR.mp3",NULL,100);
if (music_number == 1) media_loop("Café Del Mar William Orbit The Story of Light.-.3astUpRoaR.mp3",NULL,100);
if (music_number == 2) media_loop("Café Del Mar Afterlife Dub Ya Mind.-.3astUpRoaR.mp3",NULL,100);
Thanks for taking the time.
|
|
|
Re: random()
[Re: Reconnoiter]
#424027
06/09/13 20:24
06/09/13 20:24
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Check out random_seed(var val). A random number generator tries to cover all digits for instance between 0 and 65535 in a seemingly random way which however is always the same when you only start with the same value. Thus you have to pick another random seed to get a different sequence with the function mentioned above. I assume that random_seed(0) grabs some additional information such as for example the clock on your computer which then leads to a calculated number "x" which is then used as random_seed(x) with x not 0.
EDIT: Btw. random(3) only returns values between 0 and lower (!) than 3, it will never return 3.
Last edited by Superku; 06/09/13 20:25.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: random()
[Re: Reconnoiter]
#424028
06/09/13 20:25
06/09/13 20:25
|
Malice
Unregistered
|
Malice
Unregistered
|
Call random_seed(0); once, before the function.. Lol funny timing EDIT - Damn I got beat.  integer(random(3)+1); right? if(1) if(2) if(3)
Last edited by Malice; 06/09/13 20:34.
|
|
|
Re: random()
[Re: Kartoffel]
#424041
06/10/13 01:30
06/10/13 01:30
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
This approach is much easier to maintain:
#include <acknex.h>
TEXT* tracks =
{
string(
"a.mp3",
"b.mp3",
"c.mp3");
}
void play_random_song()
{
int nr = random(tracks->strings);
media_play((tracks->pstring)[nr],NULL,100);
}
void main()
{
random_seed(0);
play_random_song();
}
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|