Search code examples
pythonstringrandomhex

Random byte string in Python


I have buf="\x00\xFF\xFF\xFF\xFF\x00"

How can I make the "\xFF\xFF\xFF\xFF" randomized?


Solution

  • >>> import os
    >>> "\x00"+os.urandom(4)+"\x00"
    '\x00!\xc0zK\x00'