中本聰骰子
具體的玩法和原理都可以參考文末的那篇文章洋只。
該游戲能很好的證明公平性的原因有兩點(diǎn)
- 1seed提前上鏈,公平性有目共睹宇姚,無人可更改频蛔。
- 2 隨機(jī)幸運(yùn)數(shù)字因人而異(在seed的基礎(chǔ)上引入了txid)
- 3上鏈采用的是寫入op return字段,實(shí)現(xiàn)方式可以參考o(jì)mni的create raw tx函數(shù):
- https://github.com/OmniLayer/omnicore/wiki/Use-the-raw-transaction-API-to-create-a-Simple-Send-transaction
梅森算法
根據(jù)隨機(jī)種子參數(shù)隨機(jī)數(shù)的算法采用的是梅森算法照雁,同時(shí)梅森旋轉(zhuǎn)算法是R蚕愤、Python、Ruby饺蚊、IDL萍诱、Free Pascal、PHP污呼、Maple砂沛、Matlab、GNU多重精度運(yùn)算庫和GSL的默認(rèn)偽隨機(jī)數(shù)產(chǎn)生器
random庫
Basic examples:
>>> random() # Random float: 0.0 <= x < 1.0
0.37444887175646646
>>> uniform(2.5, 10.0) # Random float: 2.5 <= x < 10.0
3.1800146073117523
>>> expovariate(1 / 5) # Interval between arrivals averaging 5 seconds
5.148957571865031
>>> randrange(10) # Integer from 0 to 9 inclusive
7
>>> randrange(0, 101, 2) # Even integer from 0 to 100 inclusive
26
>>> choice(['win', 'lose', 'draw']) # Single random element from a sequence
'draw'
>>> deck = 'ace two three four'.split()
>>> shuffle(deck) # Shuffle a list
>>> deck
['four', 'two', 'ace', 'three']
>>> sample([10, 20, 30, 40, 50], k=4) # Four samples without replacement
[40, 10, 50, 30]
random的幾種真值分布
文章索引
1 圖文詳解Bch賭博游戲SatoshiDice公平性證明
2 談?wù)劽飞D(zhuǎn):算法及其爆破
3 Generate pseudo-random numbers
4 你真的用好了Python的random模塊嗎
5 泊松分布和指數(shù)分布