[Tutor] os.urandom()

Alan Gauld alan.gauld at btinternet.com
Sun Aug 8 00:26:57 CEST 2010


"Richard D. Moores" <rdmoores at gmail.com> wrote

>>>> import os
>>>> os.urandom(6)
> b'\xd1\xfc\xb0\x14\xeaL'
>
> So what is this output? What in ascii? What in hex?  Do those
> questions even make sense?

The documentation tells you:

os.urandom(n)¶

Return a string of n random bytes suitable for cryptographic use.

So its a string of 5 bytes(*) generated at random by some random
generator function in your OS. What do you not understand?
What did you expect?

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.

Does that help?
-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/





More information about the Tutor mailing list