Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (AndrewAMD, TipmyPip, OptimusPrime), 15,359 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
random() #424023
06/09/13 20:02
06/09/13 20:02
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline 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.

Code:
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 Offline
Senior Expert
Superku  Offline
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

M
Malice
Unregistered
Malice
Unregistered
M



Call random_seed(0); once, before the function..

Lol funny timing

EDIT - Damn I got beat. laugh

integer(random(3)+1); right?
if(1)
if(2)
if(3)

Last edited by Malice; 06/09/13 20:34.
Re: random() [Re: ] #424031
06/09/13 21:07
06/09/13 21:07
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
^ yes.


POTATO-MAN saves the day! - Random
Re: random() [Re: Kartoffel] #424041
06/10/13 01:30
06/10/13 01:30
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
This approach is much easier to maintain:
Code:
#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...
Re: random() [Re: Uhrwerk] #424191
06/11/13 17:28
06/11/13 17:28
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
That works perfect Uhrwerk, tyty. And thanks all the others too!


Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1