Jump to content

Does SRandom() have to affect all Random() that follow it?


Recommended Posts

Hello,

Once SRandom() is started for a certain Random(), how can I turn it off for other Random() later in my script?

I do not want the SRandom() to affect all the Random() in my script, just certain Random() along the way.

I use Random() throughout my script, and I want some seeded and others not seeded.

I do not want to have to declare all the Random() [edit: ie all the Random() that I do not want to be affected by the SRandom()] variables at the top of the script before SRandom() starts.

For example, in this code, I want $x to always be affected by the SRandom (which it is), but I want $i to always be a different random number, ie not affected by the SRandom.

SRandom(125)
$x = Random(1, 100, 1)
MsgBox(0, '', $x, 1);$x is always 23 here, which is what
                 ; I want, a seeded random number, very good

$i = Random(1, 100, 1)
MsgBox(0, '', $i, 1);$i is always 55 here, but I want it to be always
                 ;a different random number, not 55 each time, so
                 ;how do I cancel SRandom() for this one?

So, within a given script, is it possible to "cancel" SRandom() along the way where I want a non-seeded Random()?

Or is it the case that once I use an SRandom() in a script, every following Random() will have to be affected by the SRandom() that has been used?

Thanks for any ideas about this.

frew

Edited by frew
Link to comment
Share on other sites

Or is it the case that once I use an SRandom() in a script, every following Random() will have to be affected by the SRandom() that has been used?

True.

If what you wanted was one string of "random numbers" that are the same every time, you could peel them off first with a fixed SRandom seed,

Then run SRandom() with some sort of seed that will change each time, as an example:

SRandom(@sec+TimerInit())

Link to comment
Share on other sites

Oh, nice...that's a very useful idea TurionAltec. Thanks so much for this

SRandom(@sec+TimerInit())
.

That works very nicely.

I was also thinking something like this, putting a random variable into any SRandom() that I that I wish to have sort of "Cancel" any previous SRandom:

$sr_Not_1 = Random(1, 12341234, 1)
$sr_Not_2 = Random(1, 12341234, 1)

SRandom(12345)
$x = Random(1, 100, 1)
MsgBox(0, '', $x, 1)

SRandom($sr_Not_1)
$i = Random(1, 100, 1)
MsgBox(0, '', $i, 1)

SRandom($sr_Not_2)
$z = Random(1, 100, 1)
MsgBox(0, '', $z, 1)

...but your idea is easier.

Thanks again!

frew

Edited by frew
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...