ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 03-03-2011
Sucharith Vanguri Sucharith Vanguri is offline
Flexsim User
 
Join Date: Mar 2010
Location: Harrisburg PA
Posts: 7
Downloads: 1
Uploads: 0
Thanks: 5
Thanked 0 Times in 0 Posts
Rep Power: 0
Sucharith Vanguri is on a distinguished road
Default Random stream initial values

How are the random streams initialized? I know that only the streams 1 to 100 are initialized automatically, I need to know the source of seed values. I was able to print out the initial seed values using a simple script; but I need the source so I can use the rest of the numbers to initialize higher streams.

Is it true that stream 0 is used to initialize all other streams?

I have also heard that the random number generator got an upgrade in V5, can someone provide more details? Did the initial number of streams change from 100?

Regards

Sucharith Vanguri
  #2  
Old 03-04-2011
Brandon Peterson's Avatar
Brandon Peterson Brandon Peterson is offline
The Flexsim Consultant
 
Join Date: Jul 2007
Location: Salt Lake City, Utah
Posts: 382
Downloads: 29
Uploads: 6
Thanks: 192
Thanked 516 Times in 235 Posts
Rep Power: 490
Brandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant future
Default

Sucharith,

The randstate() command can be used to get the current random seed value for a given random number stream. The easiest way to view how Flexsim is treating the random number streams is to return the value from this command in a script window and execute it at different times.

If you have repeat random number streams on then you will notice that the seed value always starts at a specific number for each individual stream. This number will be the same for that stream every time on every computer. It is done that way so that it is possible for two individuals to run the exact same simulation on two different computers (i.e. tech support).

If you are not repeating the random number streams then the seed value at the end of one simulation run is used as the starting value for the next simulation run.

A method for initializing 100+ random number streams would be to use a random variable created by another sub-100 random number stream. If you do this the same way every time then the numbers will be the same every time if you are repeating random number streams and different if you are not.

Code:
for(int i = 100; i <= 199; i++)
{
    randinit(i, duniform(1, 2147483647, 0));
}
Good Luck,
Brandon
__________________
thats not normal.

Last edited by Brandon Peterson; 03-04-2011 at 05:23 PM. Reason: Changed duniform() code
The Following User Says Thank You to Brandon Peterson For This Useful Post:
Scott Mackay (03-08-2011)
  #3  
Old 03-04-2011
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 773
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

There's also this post which may help.
  #4  
Old 03-04-2011
Sucharith Vanguri Sucharith Vanguri is offline
Flexsim User
 
Join Date: Mar 2010
Location: Harrisburg PA
Posts: 7
Downloads: 1
Uploads: 0
Thanks: 5
Thanked 0 Times in 0 Posts
Rep Power: 0
Sucharith Vanguri is on a distinguished road
Default

Brandon,

Thanks for the clarification. I understand that I can use randstate() command to find out the current seed value, but I thought it will be beneficial if I knew what the source of the seed values so that I can continue to pull seed values from the same source and use them for higher numbered streams. That is if at all there is a logical order to the seed values for streams 1 to 100.

Jason,

Thanks for the pointer. I did read that thread and actually like the use of duniform() better than uniform() to provide an integer seed value. I also see that you have used stream 0 as your seed stream. This is where I actually wanted to know if the whole purpose of stream 0 is to provide seed values.

If I were to automate and control the stream initialization it will be easy and elegant to control all streams with seed values from one soure.

Thanks

Sucharith Vanguri
  #5  
Old 03-04-2011
Sucharith Vanguri Sucharith Vanguri is offline
Flexsim User
 
Join Date: Mar 2010
Location: Harrisburg PA
Posts: 7
Downloads: 1
Uploads: 0
Thanks: 5
Thanked 0 Times in 0 Posts
Rep Power: 0
Sucharith Vanguri is on a distinguished road
Default

It just hit me that initializing streams using sequential numbers from a source stream will not work. Hope I am right on this one, if not please correct me.

Let's say stream 0 will generate the following values sequentially
123
456
789
147
258
369

If I use 123 as seed fro stream 101, 456 for stream 102, and so on; the values from stream 101 and 102 will be the same except that it shifted by 1 position.

stream 101 will generate 123, 456, 789, 147, 258, 369 ...
stream 102 will generate 456, 789, 147, 258, 369 ...

This is because the seed value of 123 will always generate 456 as the next number irrespective of the stream number. Am I right?

Going back to Jason's script for initializing streams, it uses the stream to generate a discrete uniform number between 1 and 2147483647 which is used as the seed. Does this process of using sequential random numbers from stream 0 passed through a duniform() function ensure that the streams do not overlap? Or is this process also impacted by the same flaw described above?

Once again thanks for all your thoughts and help.

Regards

Sucharith Vanguri
  #6  
Old 03-04-2011
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 773
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

No that's not how it typically works because you've assumed the stream that 101 generates is the same as the one from stream zero, yet we know that the seed for stream zero was 1 (the replication number), and not 123.

Add this code onto the reset code in the other post and create a global table called 'testtable'. It creates samples from the newly initialized streams and places each stream's samples set in a column. They should be uncorrelated.

Code:
treenode testtable=reftable("testtable");
clearcontents(testtable);
int samplesize=20;
int numstreams=7;
settablesize(testtable,samplesize,numstreams);
for (int stream =numstreams;stream>0;stream --){
	setname(gettablecell(testtable,1,stream),concat("Stream ",numtostring(stream+streambase,0,0)));
	for (int n=1;n<=samplesize;n++){
		setname(rank(testtable,n),concat("Sample:  ",numtostring(n,0,0)));
		settablenum(testtable,n,stream,duniform(1,2147483647,stream+streambase));
	}
}

Last edited by Jason Lightfoot; 03-04-2011 at 02:08 PM.
The Following 3 Users Say Thank You to Jason Lightfoot For This Useful Post:
Scott Mackay (03-08-2011)
  #7  
Old 03-04-2011
Brandon Peterson's Avatar
Brandon Peterson Brandon Peterson is offline
The Flexsim Consultant
 
Join Date: Jul 2007
Location: Salt Lake City, Utah
Posts: 382
Downloads: 29
Uploads: 6
Thanks: 192
Thanked 516 Times in 235 Posts
Rep Power: 490
Brandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant future
Default

Sucharith,

You are confusing the result with the stream location, they are not the same thing. Initializing a random number stream to 105 will not return a value of 105. So in your example stream 101 would start in location 123 giving a specific result x and stream 102 would start in location 456 giving a result y. Assuming that the random number streams are all pulling values from the same sequence of numbers (I'm not sure either way) then stream 101 would not repeat the values of stream 102 until 351 random number requests were made.

The code that I posted and the code in the post that Jason referenced will both initialize the random number streams in a repeatable way that (unless it randomly occurs) will not result in any of the random number streams repeating one another for a very long time.

There is no source that I know of for the default (repeat) starting value for random number streams 1 - 99. They are specific numbers that don't change regardless of the computer Flexsim is installed on or the time at which the model is run. The repeat values are also the default starting values for the streams when Flexsim is opened.

I don't know if you are just curious or trying to initialize streams in robust, repeatable, and statistically sound manner. If you are curious then I can't help you further because I don't have access to the engine code.

If it is the later then you have everything you need from Jason and myself. Because, functionally it doesn't matter if the default stream starting locations are from some source stream or hard coded; either way they are what they are and they don't change. If you randomly select starting locations for your streams in a manner that you can duplicate (repeat) if you need to, then you will be OK and get good results.

One could argue that maybe there is some optimal starting location for each stream and that they should all be started some minimum distance from any other stream. Another would argue that the first person is trying to impose a logical and uniform approach to randomness and that instead of randomly random numbers they will end up with their random numbers. If you go much further it just gets more silly; so much so, that smart people will start to sound dumb and random numbers start to look sequential.

Good Luck,
Brandon
__________________
thats not normal.
The Following User Says Thank You to Brandon Peterson For This Useful Post:
Scott Mackay (03-08-2011)
  #8  
Old 03-07-2011
Sucharith Vanguri Sucharith Vanguri is offline
Flexsim User
 
Join Date: Mar 2010
Location: Harrisburg PA
Posts: 7
Downloads: 1
Uploads: 0
Thanks: 5
Thanked 0 Times in 0 Posts
Rep Power: 0
Sucharith Vanguri is on a distinguished road
Default

Brandon,

Thank you for the clarification. I am aware that the random seed will not be the output; I am sorry I was not clear when I wrote my post. I am trying to get a handle on random number stream in order to control or initialize or change the stream values between replications. This is important for the work I am pursuing and very much appreciate your help.

I wrote a small script to answer my question. I basically two consecutive seed values from stream 0 to initialize two new streams 200 and 201. Then I basically used randnext() and randstate() commands in a loop to obtain seed values from both the streams. The output showed that seed values from stream 200 are the same as 0 and stream 201 was offset by 1.

intarray seedAr=makearray(10);

randinit(0,0);
for (int seed=1; seed<=10;seed++)
{
seedAr[seed]=randstate(0);
randnext(0);
}

randinit(200,seedAr[1]);
randinit(201,seedAr[2]);

intarray strAr1=makearray(10);
intarray strAr2=makearray(10);

for (int strInc=1; strInc<=10;strInc++)
{
strAr1[strInc]=randstate(200);
randnext(200);
strAr2[strInc]=randstate(201);
randnext(201);
}
pt("Seed 1\t\t Stream 200\t\t Stream 201");pr();
for(int cnt=1; cnt<=10; cnt++)
{
pd(seedAr[cnt]);pt("\t\t");
pd(strAr1[cnt]);pt("\t\t");
pd(strAr2[cnt]);pr();
}

Output:

Seed 1 Stream 200 Stream 201
1973272912 1973272912 860127133
860127133 860127133 1317664762
1317664762 1317664762 931142530
931142530 931142530 822507670
822507670 822507670 1086919201
1086919201 1086919201 1522821923
1522821923 1522821923 397488321
397488321 397488321 1790163750
1790163750 1790163750 1387737905
1387737905 1387737905 806491222

So this brings be back to my original question as to the best approach to initialize streams above 100. Also I agree with you that any greater control over the random number generation process will deprive the randomness from already “pseudo” random numbers. Pursuing this quest for higher random streams has been enlightening.

Regards
Sucharith Vanguri
  #9  
Old 03-08-2011
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 773
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

You're not using the random value returned by randnext(0) to initialize the streams 200 & 201. Your code initializes them as offsets from the starting position of stream zero - as proven by your output.

Change the statement seedAr[seed]=randstate(0); to seedAr[seed]=randnext(0)*2147483647; and you will have different stream starting positions.

I strongly suggest you use the code as provided in the earlier links.
The Following 2 Users Say Thank You to Jason Lightfoot For This Useful Post:
Sucharith Vanguri (03-09-2011)
  #10  
Old 03-08-2011
Brandon Peterson's Avatar
Brandon Peterson Brandon Peterson is offline
The Flexsim Consultant
 
Join Date: Jul 2007
Location: Salt Lake City, Utah
Posts: 382
Downloads: 29
Uploads: 6
Thanks: 192
Thanked 516 Times in 235 Posts
Rep Power: 490
Brandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant future
Default

Sucharith,

As I stated earlier, you are confusing the result with the stream location. The numbers you are printing out are the stream locations, and even though they don't appear to be sequential they are. So essentially your code is printing out the first 10 sequential numbers for stream 0 and setting the starting points for stream 200 to spot 1 and 201 to spot 2. So, they likewise print out the same (200) and +1 (201) sequential numbers.

To get a random starting location for 200 and 201 you need to use a random number generated by stream zero, not the stream location as you have been.

If you replace line 7 in your code:
randnext(0);
with:
randinit(199 + seed, uniform(0,2147483647,0));

then I believe that you will get the result you are looking for.

Good Luck,
Brandon
__________________
thats not normal.
The Following 2 Users Say Thank You to Brandon Peterson For This Useful Post:
Sucharith Vanguri (03-09-2011)
  #11  
Old 03-09-2011
Sucharith Vanguri Sucharith Vanguri is offline
Flexsim User
 
Join Date: Mar 2010
Location: Harrisburg PA
Posts: 7
Downloads: 1
Uploads: 0
Thanks: 5
Thanked 0 Times in 0 Posts
Rep Power: 0
Sucharith Vanguri is on a distinguished road
Default

Thanks folks, for clearing this for me.

Based on your suggestions I modified my earlier test script to the following.

intarray seedAr=makearray(10);
clearconsole();
randinit(0,0);
for (int seed=
1; seed<=10;seed++)
{
seedAr[seed]=
randstate(0);
randnext(0);
}
randinit(0,0);
randinit(200,duniform(0,2147483647,0));
randinit(201,duniform(0,2147483647,0));
doublearray strAr1=
makearray(10);
doublearray strAr2=
makearray(10);
for (int strInc=
1; strInc<=10;strInc++)
{
strAr1[strInc]=
uniform(0,1,200);//randstate(200);
//randnext(200);
strAr2[strInc]=uniform(0,1,201);//randstate(201);
//randnext(201);
}
pt("Seed 1\t\t Stream 200\t\t Stream 201");pr();
for(int cnt=
1; cnt<=10; cnt++)
{
pd(seedAr[cnt]);pt("\t\t");
pf(strAr1[cnt]);pt("\t\t");
pf(strAr2[cnt]);pr();
}


OUTPUT
================================================== ===

Seed 1 Stream 200 Stream 201
1973272912 0.898932 0.377607
860127133 0.216994 0.350879
1317664762 0.430535 0.767218
931142530 0.521343 0.249703
822507670 0.250432 0.913800
1086919201 0.372443 0.383473
1522821923 0.512322 0.983709
397488321 0.476989 0.251441
1790163750 0.804979 0.513237
1387737905 0.935315 0.726921

So the two streams are producing different values.

Thanks again.

Regards

Sucharith Vanguri
  #12  
Old 03-10-2011
Anthony Johnson's Avatar
Anthony Johnson Anthony Johnson is offline
Manager of Product Development
 
Join Date: Jul 2007
Posts: 440
Downloads: 86
Uploads: 4
Thanks: 171
Thanked 899 Times in 288 Posts
Rep Power: 735
Anthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond repute
Default Updates to the random number generator in v5.

For version 5, in addition to the Prime Modulus Multiplicative Linear Congruential Generator described here, we added an optional Combined MRG, which is implemented based on appendix 7B of Averill Law's 4th Edition. By default, however, Flexsim still uses the PMMLCG.

To enable the composite generator, call the following command: maintenance(49, 1). You can do this as part of your model's on open code.

When the composite generator is enabled, each stream contains 6 seed values instead of just 1. The parameters for the following commands are adjusted as follows:
randinit(stream, seed1, seed2, seed3, seed4, seed5, seed6)
randstate(stream, seednr)

Unfortunately, we haven't updated the parameter checking in flexscript for these commands, so if you use these parameters in flexscript, you'll get flexscript warnings. You can ignore them by minimizing the compiler console. We'll get this updated in the next version.

As before, only 100 streams are automatically initialized by Flexsim, so if you use more than that, you'll need to initialize them yourself.
The Following 2 Users Say Thank You to Anthony Johnson For This Useful Post:
Sucharith Vanguri (03-10-2011)
  #13  
Old 03-10-2011
Sucharith Vanguri Sucharith Vanguri is offline
Flexsim User
 
Join Date: Mar 2010
Location: Harrisburg PA
Posts: 7
Downloads: 1
Uploads: 0
Thanks: 5
Thanked 0 Times in 0 Posts
Rep Power: 0
Sucharith Vanguri is on a distinguished road
Thumbs up

Anthony,

Thank you for providing the process to use CMRG. I have heard about it but this information is really useful. Glad to know of its existence.

Regards

Sucharith Vanguri

Tags
random streams, seed values


Thread Thread Starter Forum Replies Last Post
How to set table values by using GUI Congshi Wang Q&A 6 05-20-2010 12:52 AM
Initial Inventory Pschilthuis Q&A 2 03-03-2010 07:44 AM
Create a table with random values Michael Hartlieb Q&A 7 08-05-2009 08:09 AM
All time related values 0,0000001 time units delayed Patrick Cap Q&A 2 05-01-2009 01:50 AM
More random random number Paul Dowling Q&A 6 06-01-2008 07:30 PM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.