Random numbers
Seeding random numbers
22/11/08 13:52 Filed in: Analysis
Statistical modelling is part of the standard
engineers tool set. The desktop computer means
running scenarios with multiple inputs an easy task
for all engineers. Most of these tools use random
numbers to generate varying outputs. The mechanics
of generating random numbers is a mathematical art
to itself, but there are some key features when
using statistical methods that need to be
understood for effective modelling.
One of these key features is the seed. Random numbers are generated using algorithms that take an input value and generate a sequence of numbers that are apparently random. The input value is called the seed. Most programmes use the time when the first random number is generated as the seed; this then ensures a different sequence is generated each time a programme is run.
Overriding the use of the time as the seed does however have a number of benefits:
● It allows scenarios to be re-run, particularly important where scenarios are used to generate the design in a safety critical situation.
● It allows scenarios to be partially re-run. By using the same input parameter the scenario can be started in the same way, but using the seed, the random number sequence can be effectively re-set. This then allows a bifurcation in the model with a different outcome part way through the model.
● It gives repeatability to models, a key component of any analysis that is quality audited. If you are having your analysis checked and it doesn't have built in auditing features such as date stamped reports, your checker must be capable of recreating identical results to yours. The only way of doing this in a statistical model such as UDEC is to set the deed of the model prior to the runs so that the checker can recreate exactly the same model.
So with all that in mind, here are a few ways of setting random number seeds in your models:
Excel
With Excel the easiest way to generate random numbers with a seed is to use the Data Analysis tool pack. I usually find that when I'm working with Excel and random numbers I'm having to use visual basic. For me setting the seed programmatically in Excel using Randomize statement.
Apple Numbers 1.0
Bad news here, I don't know how to set the seed in numbers. It doesn't really surprise me given the lack of scripting associated with Numbers. I remain hopeful of many improvements in the next version of Numbers and this is definitely one of them.
Cocoa
In Cocoa just use the srandom() function. There are plenty of examples out there with this in.
Applescript
In Applescript just set the seed when you first generate a random number using set firstRandom to random number from 1 to 100 with seed seedValue. I've been using this with no problems on an Application that I am currently writing in Applescript Studio. One thing to be aware of though is the some item of function. This doesn't seem to respond to seeding so well so other methods of taking a random value from a list using a directly generated random number seem to work better.
One of these key features is the seed. Random numbers are generated using algorithms that take an input value and generate a sequence of numbers that are apparently random. The input value is called the seed. Most programmes use the time when the first random number is generated as the seed; this then ensures a different sequence is generated each time a programme is run.
Overriding the use of the time as the seed does however have a number of benefits:
● It allows scenarios to be re-run, particularly important where scenarios are used to generate the design in a safety critical situation.
● It allows scenarios to be partially re-run. By using the same input parameter the scenario can be started in the same way, but using the seed, the random number sequence can be effectively re-set. This then allows a bifurcation in the model with a different outcome part way through the model.
● It gives repeatability to models, a key component of any analysis that is quality audited. If you are having your analysis checked and it doesn't have built in auditing features such as date stamped reports, your checker must be capable of recreating identical results to yours. The only way of doing this in a statistical model such as UDEC is to set the deed of the model prior to the runs so that the checker can recreate exactly the same model.
So with all that in mind, here are a few ways of setting random number seeds in your models:
Excel
With Excel the easiest way to generate random numbers with a seed is to use the Data Analysis tool pack. I usually find that when I'm working with Excel and random numbers I'm having to use visual basic. For me setting the seed programmatically in Excel using Randomize statement.
Apple Numbers 1.0
Bad news here, I don't know how to set the seed in numbers. It doesn't really surprise me given the lack of scripting associated with Numbers. I remain hopeful of many improvements in the next version of Numbers and this is definitely one of them.
Cocoa
In Cocoa just use the srandom() function. There are plenty of examples out there with this in.
Applescript
In Applescript just set the seed when you first generate a random number using set firstRandom to random number from 1 to 100 with seed seedValue. I've been using this with no problems on an Application that I am currently writing in Applescript Studio. One thing to be aware of though is the some item of function. This doesn't seem to respond to seeding so well so other methods of taking a random value from a list using a directly generated random number seem to work better.