log*_*ick 1 hex cryptography julia
我正在尝试为区块链钱包应用程序生成一个随机的十六进制字符串,但我不确定如何在 Julia 中执行此操作。在Python中,我会做类似的事情
import os
from ecdsa import SigningKey, VerifyingKey, SECP256k1
seed = os.urandom(SECP256k1.baselen)
Run Code Online (Sandbox Code Playgroud)
您可以使用randstring指定允许的字符:
julia> using Random
# default length is 8 characters
julia> randstring(['0':'9'; 'a':'f'])
"e7e15070"
# other custom lengths
julia> randstring(['0':'9'; 'a':'f'], 4)
"9a6a"
julia> randstring(['0':'9'; 'a':'f'], 12)
"df398edb1937"
Run Code Online (Sandbox Code Playgroud)
julia> bytes2hex(rand(UInt8, 4))
"9fae741a"
Run Code Online (Sandbox Code Playgroud)
rand并randstring默认使用MersenneTwister伪随机数生成器。如果您想使用不同的随机数流,您可以使用RandomDevice:
julia> randstring(RandomDevice(), ['0':'9'; 'a':'f'])
"6f4499e3"
julia> bytes2hex(rand(RandomDevice(), UInt8, 4))
"4d1c035c"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
484 次 |
| 最近记录: |