Date: Sun, 06 Oct 2002 01:02:56 -0700 (PDT) From: =?ISO-8859-1?Q?Mikko_Ty=F6l=E4j=E4rvi?= <mbsd@pacbell.net> To: Peter Leftwich <Hostmaster@Video2Video.Com> Cc: FreeBSD Questions LIST <FreeBSD-Questions@FreeBSD.Org> Subject: Re: /dev/urandom is randomly cool Message-ID: <20021006005506.W308-100000@atlas.home> In-Reply-To: <20021005223308.D2062-100000@dhcp-407-32.san.rr.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 5 Oct 2002, Peter Leftwich wrote: > I was sorting through my /usr/X11R6/bin/startx text-file and noticed: > > mcookie=`dd if=/dev/urandom bs=16 count=1 2>/dev/null | hexdump -e \\"%08x\\"` > > I started playing around with `cat /dev/urandom` and `head -1 /dev/urandom` > so my question is... How can I use the head -1 method and change the output > into just [A-Za-z0-9] and no spaces or punctuation? And specify length? Why head -1...? /dev/random isn't very line oriented. Oh, well, nevermind. One way of doing what you want is: tr -cd a-zA-Z0-9 < /dev/urandom | dd bs=$len count=1 2>/dev/null Which will give you $len random bytes from the set a-zA-Z0-9 (it reads a lot more from /dev/urandom than it produces though). Another answer is, as always, "use perl" :-) $.02, /Mikko To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021006005506.W308-100000>