How can I generate different sequences of uniformly distributed random numbers by using a different random seed for every run?
OPL script provides the user with a couple of functions to manage the generation of uniformly distributed random numbers:
1) srand(n)- Used to initialize the generator (seed) for the pseudo random numbers.
2) rand(m)- Returns a pseudo random integer modulo m (thus the number will be between 0 and m-1, both inclusive).
If you would like to generate different random numbers every time you ran your OPL model, then you will need to use the srand function to provide a different random seed for each run. Time could serve as one such seed and hence the subsequent rand function calls would generate different random numbers in every run. One such implementation using OPL scripts could look like the following:
var now = new Date();
int myRange = 60;
int randomArray[i in 1..20] = 1 + rand(myRange);
|Business Integration||IBM ILOG CPLEX Optimization Studio||Area:ILOG Script for OPL/OPL Script||AIX, Linux, Windows||220.127.116.11, 12.5, 12.4, 12.3, 18.104.22.168, 12.2||All Editions|