Jump to content


Photo

irandom_range(x1,x2) returns the same value


  • Please log in to reply
12 replies to this topic

#1 KingDragonRider

KingDragonRider

    KDR Productions

  • GMC Member
  • 166 posts
  • Version:GM:Studio

Posted 23 June 2012 - 10:43 AM

Hi,

I am making a multiplication game and I have 2 variables which are the two numbers being multiplied together and is determined by the irandom_range(x1,x2) function. However each time I test it, it comes up with the same combination every time, 7x7, 7x2, 8x4 ..., which completely beats the object of the game! :P

If this could be sorted out that would be great! :)

:thanks:

KingD.
  • 0

#2 YellowAfterlife

YellowAfterlife

    GMC Member

  • Global Moderators
  • 3490 posts
  • Version:GM:Studio

Posted 23 June 2012 - 11:31 AM

Try adding a call to function randomize() in game start. This would set generator seed to a time-dependent value, thus leading to different results on each game launch.
  • 0

#3 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 1452 posts
  • Version:GM8.1

Posted 23 June 2012 - 01:07 PM

if you call the random() function in the beginning of your game it will be different each time.
  • 0

#4 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16790 posts
  • Version:GM:Studio

Posted 23 June 2012 - 01:17 PM

All games start with the same random seed in GM:Studio. This makes it MUCH easier to debug as the results will not change from one test run to the next... however it also means that (as Y.A.L. said) you need to call the randomise() function at the start of the game (in the room start or the create event of the first object in the game).
  • 0

#5 KingDragonRider

KingDragonRider

    KDR Productions

  • GMC Member
  • 166 posts
  • Version:GM:Studio

Posted 23 June 2012 - 06:35 PM

All games start with the same random seed in GM:Studio. This makes it MUCH easier to debug as the results will not change from one test run to the next... however it also means that (as Y.A.L. said) you need to call the randomise() function at the start of the game (in the room start or the create event of the first object in the game).


I have tried it in Game Start and the creation event of the control object but nothing happened so I'll see if it works for the room creation event..

Cheers,
KingD.

EDIT: I put it in Room Creation and still it came up with the same 7x7, 7x2 etc.. All I need to do is just put randomise() at the beginning of the script? Nothing else?

Edited by KingDragonRider, 23 June 2012 - 06:38 PM.

  • 0

#6 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 4686 posts
  • Version:GM8

Posted 24 June 2012 - 06:36 AM

Post your code.

Randomization works just fine for me in GM8.0, being different results every time. ... Actually don't know if I ever checked with irandom_range() though.
  • 0

#7 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16790 posts
  • Version:GM:Studio

Posted 24 June 2012 - 08:43 AM

Could you please post what code you are using? I suspect that you are using the random range function erroneously... and even if you aren't it would help greatly!

Randomization works just fine for me in GM8.0, being different results every time. ... Actually don't know if I ever checked with irandom_range() though.

GMStudio is different. It always uses the same seed at the start of a game to make debugging simpler.
  • 2

#8 wagdog

wagdog

    GMC Member

  • GMC Member
  • 270 posts
  • Version:GM:Studio

Posted 24 June 2012 - 02:17 PM

As mentioned above, randomize() will use a random seed.

You could also use the random_set_seed(seed) function to force the random num generator to use the same seed, and return the same sequence of random numbers - useful for debugging, or for using the same sequence of random numbers.
  • 0

#9 KingDragonRider

KingDragonRider

    KDR Productions

  • GMC Member
  • 166 posts
  • Version:GM:Studio

Posted 27 June 2012 - 08:10 PM

Sorry guys, I was away for a while.

Here's the relevant parts of my code:

//Creation event of controller object...
  randomize();
  n1 = get_integer("What is the lowest number you want to multiply with?", 2);
  n2 = get_integer("What is the highest number you want to multiply with?", 12);
  number[0] = irandom_range(n1,n2);
  number[1] = irandom_range(n1,n2);
  
  ans = number[0]*number[1];

KingD.
  • 0

#10 NRV

NRV

    GMC Member

  • New Member
  • 12 posts
  • Version:GM:Studio

Posted 12 July 2012 - 02:07 AM

Maybe you already know, but.. from the help in version 1.0.263:

"randomize();
This function sets the seed to a random value.
Note : Even this is affected by the seed! If you set the seed, randomized it, then set the seed back again and randomized again, both randomizations would result in the same seed."

So it doesn't seem to work right now.. at least not like before, I believe in GM 8 it worked "correctly". I mean.. I want "randomize()" to give me a different seed every time I start a game :)

For now I am using:
random_set_seed(get_timer());
..and it seems to work :)
  • 1

#11 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14384 posts
  • Version:GM:Studio

Posted 12 July 2012 - 06:31 PM

Pretty sure it's a randomize() studio bug. I fixed another guy's same problem using

random_set_seed(current_time);

which is basically what randomize probably does.

That fixed the other guy's problem.

Just call it once when the game starts.
  • 0

#12 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16790 posts
  • Version:GM:Studio

Posted 12 July 2012 - 06:50 PM

It appears that current_time is bugged in Studio... So the solution of random_set_seed(get_timer()) is the best all round one...
  • 0

#13 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14384 posts
  • Version:GM:Studio

Posted 12 July 2012 - 07:30 PM

I also totally missed post #10 for some reason.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users