It is currently Thu, 20 Jan 2022 10:03:54 GMT



 
Author Message
 Random alphanumeric sequence parsing
I would like to use /dev/urandom (linux red hat 7.3 kernel 2.4) to
generate long sequence of alphanumeric characters. I used the below
mentioned command but I got several lines while I'd like to have an
"uninterrupted" stream of characters. Any idea or corrections?
Thank you in advanced.

[root]# cat </dev/urandom | head -n 15 | sed -e 's/[^0-9a-zA-Z]//g'|
sed -e 's/\\n//g'
MTAyR9HiLj
GIQ3a9bPRBoz
IwrUkGeECxzbqygZUdq3xkbNQtNIjsy9kwKQaT28geXNVaPMZrvWzqkOv6FFSUKpaHAtPNK20873BFC5VBh7lQs1l0FmX15hzrIilMe5a
kq9ZNMD2iHX3GtCEtgdLuDjRvMwLmsbrb996KZBgeAs3CyOTqKiXV3khlx1EYYnFH355dqf19LEfIcy3xM9Xs9G6g4SYhNpx
PpJZbCGWKkJ8xqedrhjpr9YSbx7M0SvWW7fh2
QmdkgK0V1b8rbPD8rrtaRez8vltePjJmRI
DSSPtQu5tz6EVbOIBHM4xMb63KRurpY7DJIqv63q979wiBPYI5a4h49HNJuURuiJ42zQYFfHsi6lAMc3c7qHP38vQHlEbvwCWMysvVZRBdn2ySd5F4cOtGzcStGVq3rYymfcUMczcM8OVOFcRknjrIsLKWXyhsnoyY
o2C6UfoDHxTuQbrClbFTnzWUD78zxZQPgbhg9dw9D3O19NXUzHwPlYDEJAoyT
mva6czuFKZlsU9irQpLm



 Sun, 10 Sep 2006 22:32:20 GMT   
 Random alphanumeric sequence parsing
2004-03-24, 06:32(-08), Sara:

tr -cd 0-9a-zA-Z < /dev/urandom

--
Stphane                      ["Stephane.Chazelas" at "free.fr"]



 Sun, 10 Sep 2006 22:50:21 GMT   
 Random alphanumeric sequence parsing

   That _is_ an "uninterrupted" stream of characters; a newline is a
   character like any other.

   Besides, when you pipe through "head -n 15", you are specifically
   asking for 15 lines. Those lines will be of random length; how long
   a string do you want?

   To remove all non alphanumeric characters, pipe the bytes through
   tr's complement option:

tr -cd 'a-zA-Z0-9'

   I have never used /dev/random, but when I tried it just now, it was
   incredibly slow. I'd use the shell to produce the string:

randstr() {
    case $1 in
        "-l") length=$2; shift 2 ;;
        *) length=1 ;;
    esac
    string=
    _RANDSTR=
    while [ ${#_RANDSTR} -lt $length ]
    do
      eval _RANDSTR=${_RANDSTR}${sep}\${$(( $RANDOM % $# + 1 ))}
    done

lower="a b c d e f g h i j k l m n o p q r s t u v w x y z"
upper="A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
numbers="0 1 2 3 4 5 6 7 8 9"

randstr -l 666 $upper $lower $numbers
echo $_RANDSTR

--
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License



 Mon, 11 Sep 2006 01:17:35 GMT   
 Random alphanumeric sequence parsing
Dnia 2004-03-24, Sara napisal:
I've recently almost the same problem, and this is my solution:

#!/bin/sh

unset PASS
for PART in `dd if=/dev/urandom bs=1024 count=10 2> /dev/null | strings`; do
  PASS="$PASS $PART"
  test ${#PASS} -gt 10 && break
done

echo "${PASS# }"
EO#!

This generates nice passwords from 11 to ~16 chars length :)

--
Stanislaw Klekot



 Wed, 13 Sep 2006 03:00:14 GMT   
 
   [ 4 post ] 

Similar Threads

1. Random TCP Sequencing

2. lex/yacc parsing: ending parse with yywrap?

3. How random is random under Linux?

4. Random Number generator not Random *****

5. Trying to generate random random numbers!

6. Random Characters with RANDOM

7. TGUI9660Xgi + ViewSonic G773: No X, Only Alphanumeric.

8. Alphanumeric Paging Software for Linux?

9. Alphanumeric paging software

10. Sendpage ( Alphanumeric Paging )


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software