Most of us will have an intuitive feeling of randomness. When a sequence of occurring something has no recognizable patterns or regularities.
But why should we at all bother about randomness? Because it is core component of simulation of any algorithm. If the random number generator component of the simulation is biased the analysis of the simulation will be incorrect. Or if the generator always generate same sequence its practically unreliable because simulations need to be run many time on different set for the purpose of analysis.
It can be used to select a random sample from a set of large data
Lets look an example of tossing a coin.
Sequence 1st seems to be less random than 2nd but actually both have same probability of occurence of 1/2^20
Which gives the birth to the next question how are we going to measure randomness. Yes you read correct measure randomness .
Some of the naive technique can be
frequency test in this test we check the frequency of each element in the sequence and make sure that each element roughly occur equal number of time
BUT if we pass a random generator on this test are not we loosing the test case where one element is excessive are not occuring { 1,1,2,1,1} a good random sequence of set {1,2}.
Also frequency test makes no difference between generator generating these two sequence frequently {1,1,1,2,2,2} {1,2,1,2,1,2} basically when element occur in the sequence is not the concern for the frequency test.
So looking for a better statical analysis of the random number is a good option (that will be whole new blog).
Generating Random Number
Option 1:
This is ok but has some major flaw because the way rand work its real randomness lies in upper bit and not the lower bits. MOD operation takes the lower bit into consideration and discards the higher order bits hence this generator will not satisfy our need.
Option 2:
This takes the upper bit into consideration but this too has flaw each time you run these two random number generator the output is same
Because on every run it is initialized with default seed. So we need a unique seed every time we need to generate random number
TIME can be that seed
Option 3:
Now you have a generator in C which generate a random sequence uniquely every time it is run.
But why should we at all bother about randomness? Because it is core component of simulation of any algorithm. If the random number generator component of the simulation is biased the analysis of the simulation will be incorrect. Or if the generator always generate same sequence its practically unreliable because simulations need to be run many time on different set for the purpose of analysis.
It can be used to select a random sample from a set of large data
Lets look an example of tossing a coin.
Sequence 1st seems to be less random than 2nd but actually both have same probability of occurence of 1/2^20
Which gives the birth to the next question how are we going to measure randomness. Yes you read correct measure randomness .
Some of the naive technique can be
frequency test in this test we check the frequency of each element in the sequence and make sure that each element roughly occur equal number of time
BUT if we pass a random generator on this test are not we loosing the test case where one element is excessive are not occuring { 1,1,2,1,1} a good random sequence of set {1,2}.
Also frequency test makes no difference between generator generating these two sequence frequently {1,1,1,2,2,2} {1,2,1,2,1,2} basically when element occur in the sequence is not the concern for the frequency test.
So looking for a better statical analysis of the random number is a good option (that will be whole new blog).
Generating Random Number
Option 1:
This is ok but has some major flaw because the way rand work its real randomness lies in upper bit and not the lower bits. MOD operation takes the lower bit into consideration and discards the higher order bits hence this generator will not satisfy our need.
Option 2:
This takes the upper bit into consideration but this too has flaw each time you run these two random number generator the output is same
Because on every run it is initialized with default seed. So we need a unique seed every time we need to generate random number
TIME can be that seed
Option 3:
Now you have a generator in C which generate a random sequence uniquely every time it is run.


