View Single Post
  #5   (View Single Post)  
Old 14th March 2009
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,125
Default

No, jot only handles 1 single range. But with a simple script that is not too difficult to do.

The nr2char.sh script uses an array $c[..] to map numbers in the range 1 to 62 to the 10 digits, 0-9 and the upper and lower case alpabetic characters.

NOTE: arrays are not a feature of the standard sh. Both the Korn shell, and recent versions of bash support arrays.
I used OpenBSD's standard ksh (a free version of the Korn shell).
Code:
#!/bin/ksh

c[1]=0
c[2]=1
c[3]=2
c[4]=3
c[5]=4
c[6]=5
c[7]=6
c[8]=7
c[9]=8
c[10]=9
c[11]=A
c[12]=B
c[13]=C
c[14]=D
c[15]=E
c[16]=F
c[17]=G
c[18]=H
c[19]=I
c[20]=J
c[21]=K
c[22]=L
c[23]=M
c[24]=N
c[25]=O
c[26]=P
c[27]=Q
c[28]=R
c[29]=S
c[30]=T
c[31]=U
c[32]=V
c[33]=W
c[34]=X
c[35]=Y
c[36]=Z
c[37]=a
c[38]=b
c[39]=c
c[40]=d
c[41]=e
c[42]=f
c[43]=g
c[44]=h
c[45]=i
c[46]=j
c[47]=k
c[48]=l
c[49]=m
c[50]=n
c[51]=o
c[52]=p
c[53]=q
c[54]=r
c[55]=s
c[56]=t
c[57]=u
c[58]=v
c[59]=w
c[60]=x
c[61]=y
c[62]=z

while read NUM ; do
   echo ${c[$NUM]}
done
A simple example with maps the nr 62 to the 'z':
Code:
$ echo 62 | nr2char.sh    
z
We now use jot(1) to generate random number from 1-62. These numbers will be converted to one of the 62 characters by nr2char.sh.
The final processing is done by 'rs(1)' to produce human friendlier output
Code:
$ jot -w %d -r 200 1.02 62.99 | nr2char.sh | rs 0 10

t  1  L  e  R  p  k  2  u  V
y  8  C  P  t  V  m  t  c  i
m  d  0  M  K  f  C  5  p  7
U  j  K  h  v  O  H  A  A  f
j  9  V  J  I  V  c  m  S  q
u  z  U  8  o  o  v  p  g  I
m  S  f  J  h  w  p  4  S  h
r  s  Q  z  P  7  l  N  C  5
o  4  Z  T  i  k  6  p  b  O
0  y  5  Q  Q  H  0  H  C  K
V  A  H  u  e  1  y  D  T  L
l  y  5  Q  d  S  T  y  d  k
o  f  O  5  y  E  X  4  Y  b
J  Z  M  F  a  B  M  C  U  v
U  v  y  U  v  v  F  5  k  5
2  c  8  x  L  B  m  F  Y  X
n  r  D  w  d  G  3  r  6  L
n  g  Q  9  U  H  c  e  F  9
I  x  F  e  7  c  Q  4  8  9
V  4  B  b  J  J  6  9  p  M
A frequency distribution of the generated numbers
Code:
 $ jot -w %d -r 62000 1.02 62.99 | sort -n | uniq -c

 958 1
1016 2
 934 3
 957 4
1010 5
 976 6
 992 7
1020 8
1025 9
 998 10
1033 11
 969 12
 999 13
 982 14
1040 15
 977 16
1023 17
1000 18
1035 19
 936 20
1000 21
 976 22
 966 23
 971 24
1014 25
 995 26
1021 27
1083 28
 994 29
1041 30
1009 31
1005 32
1004 33
1003 34
1069 35
1070 36
 997 37
 991 38
 979 39
 993 40
1005 41
 974 42
1015 43
1026 44
1030 45
1020 46
 962 47
 993 48
 999 49
 971 50
1011 51
 991 52
1006 53
1013 54
 983 55
 968 56
1038 57
 985 58
 970 59
 993 60
 969 61
1017 62
Of 62000 generated numbers, each number should be generated about 1000 times, which it does using a simple eyeball check.

Of course real freaks would do a chi square test to make sure these numbers are random. Any volunteers? IIRC Knuth provided such a test in
his "Seminumerical Algorithms (Vol II)"

The initialization of the array c[i] of the nr2char.sh script was generated by the following script
Code:
$ cat generate.sh

TEMP=all_chars

jot -c 10 48 57 >$TEMP 
jot -c 26 A Z   >>$TEMP
jot -c 26 a z   >>$TEMP

cat -n $TEMP | sed -e 's/^  *//' -e 's/^/c[/' -e 's/    /]=/'
Attached Files
File Type: sh nr2char.sh (544 Bytes, 98 views)
File Type: sh generate.sh (150 Bytes, 84 views)
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote