Pseudo-random numbers/Xorshift star: Difference between revisions
Content added Content deleted
(Realize in F#) |
|||
Line 83: | Line 83: | ||
=={{header|F_Sharp|F#}}== |
|||
===The Functions=== |
|||
<lang fsharp> |
|||
// Xorshift star. Nigel Galloway: August 14th., 2020 |
|||
let fN=(fun(n:uint64)->n^^^(n>>>12))>>(fun n->n^^^(n<<<25))>>(fun n->n^^^(n>>>27)) |
|||
let Xstar32=Seq.unfold(fun n->let n=fN n in Some(uint32((n*0x2545F4914F6CDD1DUL)>>>32),n)) |
|||
let XstarF n=Xstar32 n|>Seq.map(fun n->(float n)/4294967296.0) |
|||
</lang> |
|||
===The Tasks=== |
|||
<lang fsharp> |
|||
Xstar32 1234567UL|>Seq.take 5|>Seq.iter(printfn "%d") |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
3540625527 |
|||
2750739987 |
|||
4037983143 |
|||
1993361440 |
|||
3809424708 |
|||
</pre> |
|||
<lang fsharp> |
|||
XstarF 987654321UL|>Seq.take 100000|>Seq.countBy(fun n->int(n*5.0))|>Seq.iter(printf "%A");printfn "" |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
(4, 20007)(2, 19937)(3, 20031)(0, 20103)(1, 19922) |
|||
</pre> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
<lang factor>USING: accessors kernel literals math math.statistics |
<lang factor>USING: accessors kernel literals math math.statistics |