Results 1 to 4 of 4
I'm using this bash script to generate 10 digit numbers:
Code:
head -c4 /dev/urandom| od -An -tu4
I have 2 issues to deal with.
1. This script often also generates ...
- 01-04-2010 #1
Help with number generation
I'm using this bash script to generate 10 digit numbers:
I have 2 issues to deal with.Code:head -c4 /dev/urandom| od -An -tu4
1. This script often also generates 9 digit numbers.
2. I would like to generate all number sequences within a specific range without having to enter this script for one number at a time.
Also a question: If I can generate number sequences within a range will they all be unique (no repeats)?
Any help is appreciated.
Script source: Text Processing Commands
- 01-06-2010 #2Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
1.
Caveat : the number may start with zero !r=$(head -n1 /dev/urandom | uuencode -m - | grep -o [0-9] | tail -n 10)
z=
for c in $r
do
z=$z$c
done
echo $z
2. Test for value z between desired range.
- 01-06-2010 #3Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
1.
This one is better, no leading zero :
Code:r=0 while [ $r -lt 999999999 ] do r=$(head -n1 /dev/urandom | uuencode -m - | tr -cd [0-9] | tail -c10) done echo $r
- 01-06-2010 #4Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
And this one sets the bounds :
Code:r=0 lbound=2000000000 ubound=2300000000 while [ $r -lt $lbound ] || [ $r -gt $ubound ] do r=$(head -n1 /dev/urandom | uuencode -m - | tr -cd [0-9] | tail -c10) done echo $r


Reply With Quote