That is a poor method since it will return a random number in the range 1..68 more often than 69..100.
While it is true that the modulus operation will return numbers in the range 1-68 more often than 69-100, this is not the reason that modulus should be avoided to change the range of random number generator. First about the range... the bash man page says:
Quote:
RANDOM Each time this parameter is referenced, a random integer between 0 and 32767 is generated. The sequence of random numbers may be initialized by assigning a value to RANDOM. If RANDOM is unset, it loses its special properties, even if it is subsequently reset.
That is 32768 possible values and you cannot distribute that in 100 bins evenly. Your algorithm will take an input of 32767 and return 101, so I tried to modify it a bit to see if I could fix that. Here is a script that shows the distributions from sb008's algorithm, my algorithm, your algorithm, and my modification to your algorithm:
As for why the modulus operation is not recommended, it tends to discard the most significant bits while our algorithms tend to discard the least significant bits. With many generators, the least significant bits are not very random. This is particularly true of linear congruential generators which is probably what bash uses.
Hi,
In our HP-UX B.11.11. I could not find dev/urandom and dev/random
Are all pseudo-devices implemented as device drivers, or in need to run /configure some package to install the package to have dev/urandom.
Please help (4 Replies)
Hi
I'm running the following command to generate a random password in a KSH script on a RHEL Linux VM but for some reason the cmd is not being closed and it's causing problems on the host.
PASSWORD="$(cat /dev/urandom | tr -dc "a-zA-Z0-9" | fold -w 16 | head -1)Aa0!"
The code worked as... (2 Replies)
Objective: To recreate the partitioning setup of /dev/sda on /dev/sdc
How would I parse the below information and initialize variables
(an array?) that can be used to build sgdisk commands in a script, regardless of the number of partitions?
Something along the lines of:
sgdisk -n... (12 Replies)
Hello AIXians,
I can't boot my AIX, it hangs and stops at the code error: 0518
After searching google, I knew the problem is due to problems in File Systems.
So the solution is booting from any bootable media, then run these commands in maintenance mode:
#fsck -y /dev/hd4
#fsck -y... (3 Replies)
Hi,
How can i check that i am using RAW devices for storage in my AIX machine...
Also after adding a LUN from storage to a aix host, when i check /dev in the host, i can see both rhdisk and hdisk with same number
eg:
dcback1(root):/dev>ls -lrt | grep disk12
crw------- 1 root ... (4 Replies)
So, we removed a LUN from the SAN and the system is refusing to remove the references to it in the /dev folder. I've done the following:
devfsadm -Cv
powermt -q
luxadm -e offline <drive path>
luxadm probe
All those commands failed to remove the path. The drive stills shows up as <drive... (13 Replies)
Hi, Anyone can help
My solaris 8 system has the following
/dev/null , /dev/tty and /dev/console
All permission are lrwxrwxrwx
Can this be change to a non-world write ??
any impact ?? (12 Replies)