Quantcast
Channel: 一言多いプログラマーの独り言
Viewing all articles
Browse latest Browse all 846

Python3で、乱数の取得

$
0
0
Python3で、乱数の取得です。これをPython+Flaskのセッション(session)用 app.secret_keyに設定すればOKですね。


$ python
>>>import os
>>>os.urandom(24)
b"'pk\x88\xb5\x1b##j\x96\xd5\xc2_\x9d\x92\x9b\xa7S7u\xaezU\x96"
>>>os.urandom(24)
b'S\xae\xeePO\xb3\xfc=\xe29\xf57\x8aW2\xa0\x15\x07H8[l\x9a@'
>>>os.urandom(24).hex()
'01758fe33950b201cd21605a8f0061db18de4afa8040e62c'
>>>os.urandom(24).hex()
'6b2c4582255b65c80573113adebbddc81bc941f98dc1b2d2'

参考サイト
Quickstart(Flask Documentation)
Pythonで/dev/urandomから乱数をゲットしてみた(三鷹台でひきこもるプログラマの日記さん)

Viewing all articles
Browse latest Browse all 846

Trending Articles