RANDOM
(16-bit) vs SRANDOM
(32-bit); 32-bit => much bigger random numbers (ie, more random numbers).
As for the randomness of the 2x variables ...
Try running:
RANDOM=5; for i in {1..10}; do echo $RANDOM; done
RANDOM=5; for i in {1..10}; do echo $RANDOM; done
RANDOM=5; for i in {1..10}; do echo $RANDOM; done
You should find that each loop generates the same set of 'random' numbers:
18499
9909
24640
15572
5516
17897
19000
12793
27730
5509
Here's a bash fiddle of the above that generates the same exact output!
Another test:
RANDOM=5; echo $RANDOM $RANDOM
RANDOM=5; echo $RANDOM $RANDOM
RANDOM=5; echo $RANDOM $RANDOM
Repeatedly generates:
18499 9909
Now repeat this test but with SRANDOM
and you should find that you cannot seed SRANDOM
and therefore each iteration generates a different set of 'random' numbers.
SRANDOM=5; echo $SRANDOM $SRANDOM
SRANDOM=5; echo $SRANDOM $SRANDOM
SRANDOM=5; echo $SRANDOM $SRANDOM
Which generates 3 different sets of output:
1355214790 3304840972
4217276959 255499591
446827805 3301635911
NOTE: Thanks to oguz ismail for the SRANDOM
output.
As for the linear
comment ...
As President James K Polk mentioned in his comment, 'linear'
probably refers to the underlying algorithm by which RANDOM
generates its not-so-random data.
Seeing how the RANDOM
output can be determined beforehand (given a starting point, aka seed
), I'd probably replace 'linear'
with something more along the lines of 'deterministic'
...
Net result ... use RANDOM
if you need to repeat a series of 'random' numbers ... use SRANDOM
if you need to generate a set of truly random numbers.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…