From owner-freebsd-questions Sun Oct 6 1: 2:58 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E07C237B401 for ; Sun, 6 Oct 2002 01:02:57 -0700 (PDT) Received: from mta5.snfc21.pbi.net (mta5.snfc21.pbi.net [206.13.28.241]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9C3E043E65 for ; Sun, 6 Oct 2002 01:02:57 -0700 (PDT) (envelope-from mbsd@pacbell.net) Received: from atlas ([64.160.45.64]) by mta5.snfc21.pbi.net (iPlanet Messaging Server 5.1 (built May 7 2001)) with ESMTP id <0H3J00EOBVOX49@mta5.snfc21.pbi.net> for FreeBSD-Questions@FreeBSD.Org; Sun, 06 Oct 2002 01:02:57 -0700 (PDT) Date: Sun, 06 Oct 2002 01:02:56 -0700 (PDT) From: =?ISO-8859-1?Q?Mikko_Ty=F6l=E4j=E4rvi?= Subject: Re: /dev/urandom is randomly cool In-reply-to: <20021005223308.D2062-100000@dhcp-407-32.san.rr.com> X-X-Sender: mikko@atlas.home To: Peter Leftwich Cc: FreeBSD Questions LIST Message-id: <20021006005506.W308-100000@atlas.home> MIME-version: 1.0 Content-type: TEXT/PLAIN; charset=US-ASCII Content-transfer-encoding: 7BIT Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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