本文簡要介紹ruby語言中 OpenSSL::Random.add
的用法。
用法
add(str, entropy) → self
將來自 str
的字節混合到偽 Random
數字生成器 (PRNG) 狀態。
因此,如果來自str
的數據對於對手來說是不可預測的,這會增加狀態的不確定性並使 PRNG 輸出的可預測性降低。
entropy
參數是(的下限)對 str
中包含多少隨機性的估計,以字節為單位。
示例
pid = $$
now = Time.now
ary = [now.to_i, now.nsec, 1000, pid]
OpenSSL::Random.add(ary.join, 0.0)
OpenSSL::Random.seed(ary.join)
相關用法
- Ruby Random.bytes用法及代碼示例
- Ruby Random.urandom用法及代碼示例
- Ruby Random.random_bytes用法及代碼示例
- Ruby Random.new_seed用法及代碼示例
- Ruby Random.seed用法及代碼示例
- Ruby Random.srand用法及代碼示例
- Ruby Random.rand用法及代碼示例
- Ruby Random.prng1 ==用法及代碼示例
- Ruby Random hex()用法及代碼示例
- Ruby Random random_number()用法及代碼示例
- Ruby Random new_seed()用法及代碼示例
- Ruby Random bytes()用法及代碼示例
- Ruby Random base64()用法及代碼示例
- Ruby Random urlsafe_base64()用法及代碼示例
- Ruby Random srand()用法及代碼示例
- Ruby Random random_bytes()用法及代碼示例
- Ruby Random rand()用法及代碼示例
- Ruby Random seed()用法及代碼示例
- Ruby Random new()用法及代碼示例
- Ruby Random uuid()用法及代碼示例
- Ruby Range.end用法及代碼示例
- Ruby Range new()用法及代碼示例
- Ruby Range.size用法及代碼示例
- Ruby Range last()用法及代碼示例
- Ruby Range.last用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Random.add。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。