[Tutor] os.urandom()

Richard D. Moores rdmoores at gmail.com
Sun Aug 8 01:32:02 CEST 2010


On Sat, Aug 7, 2010 at 15:26, Alan Gauld <alan.gauld at btinternet.com> wrote:

> Python is telling you its bytes with the b at the front.
> The \x tells you they are hex values.
>
> (*)The fact its 5 is odd since you seem to pass 6 as an argument!
> When I try it I get 6 bytes back.

Yes, the number of bytes seems to <= 6, or is it?:
>>> os.urandom(6)
b'\xf1\x1c\x15\x83\x14\x0e'
>>> os.urandom(6)
b'l\xbb\xae\xb7\x0ft'
>>> os.urandom(6)
b'\x1f\x00~\xfbz\x98'
>>> os.urandom(6)
b'\x98\xd2\xb2\xaa\x9bv'
>>> os.urandom(6)
b'2\x07\x81v\n-'
>>> os.urandom(6)
b'\x93\x1d\x1a\xa1\x0e\x1d'
>>> os.urandom(6)
b'`G\xa9_\xbab'
>>> os.urandom(6)
b'\r\xb0?p\x85\xc7'
>>> os.urandom(6)
b'\xb5\x1cn!\x93\xf4'
>>> os.urandom(6)
b'M\x0f\x1f34B'

And what's with the l in b'l\xbb\xae\xb7\x0ft' ?
the 2 in b'2\x07\x81v\n-' ?
the `G in b'`G\xa9_\xbab' ?
the \r in b'\r\xb0?p\x85\xc7' ?
the M in b'M\x0f\x1f34B' ?

Alan, are you using Windows, as I am?

I apologize to all for not explaining what I'm trying to accomplish. I
just ran across os.urandom() and am trying to understand it. I have a
script that I use to create passwords for my various website accounts,
<http://tutoree7.pastebin.com/31AisCq1>, but wondered if
website-permitted, but stronger passwords could be generated with the
use of os.urandom(). At this point, I think not.

(To Steven D'Aprano: yeah I know now, thanks to you, that the
organization and modularization of >
<http://tutoree7.pastebin.com/31AisCq1> is woefully deficient :) )

Dick


More information about the Tutor mailing list