Pseudo-random numbers/Splitmix64: Difference between revisions
Content added Content deleted
(→Phix) |
(add RPL) |
||
Line 1,363: | Line 1,363: | ||
3: 19,978 |
3: 19,978 |
||
4: 20,030 |
4: 20,030 |
||
</pre> |
|||
=={{header|RPL}}== |
|||
RPL offers hundreds of instructions and commands but, strangely, bitwise operations are limited to the set defined for the HP-16C RPN calculator in 1982. |
|||
So, to shift an integer n times, we can either stay in low gear, shifting one bit at a time: |
|||
≪ 1 SWAP '''START''' SR '''NEXT''' |
|||
≫ '<span style="color:blue">SRn</span>' STO |
|||
or play with the gearbox: |
|||
≪ |
|||
8 MOD LAST / IP ROT <span style="color:grey">@ q, r = divmod(n,8)</span> |
|||
'''IF''' SWAP THEN 1 LAST '''START''' SRB '''NEXT END''' <span style="color:grey">@ q, r = divmod(n,8)</span> |
|||
'''IF''' SWAP '''THEN''' 1 LAST '''START''' SR '''NEXT END''' <span style="color:grey">@ shift & bit right, r times</span> |
|||
≫ '<span style="color:blue">SRn</span>' STO |
|||
The first version is less efficient in terms of response time, but more idiomatic because it takes much less time to type on a calculator keyboard. |
|||
{{works with|HP|28}} |
|||
≪ # 9E3779B97F4A7C15h 'STATE' STO+ |
|||
<span style="color:green">STATE</span> DUP 30 SRn XOR # BF58476D1CE4E5B9h * |
|||
DUP 27 <span style="color:blue">SRn</span> XOR # 94D049BB133111EBh * |
|||
DUP 31 <span style="color:blue">SRn</span> XOR |
|||
≫ '<span style="color:blue">NEXTINT</span>' STO |
|||
≪ <span style="color:blue">NEXTINT</span> B→R 2 64 ^ / |
|||
≫ '<span style="color:blue">NEXTFLOAT</span>' STO |
|||
≪ # 1234567d '<span style="color:green">STATE</span>' STO |
|||
1 5 '''START''' <span style="color:blue">NEXTINT</span> '''NEXT''' |
|||
≫ '<span style="color:blue">TASK1</span>' STO |
|||
≪ { 5 } O CON |
|||
1 10000 '''START''' |
|||
<span style="color:blue">NEXTFLOAT</span> 5 * CEIL DUP2 GET 1 + PUT '''NEXT''' |
|||
≫ '<span style="color:blue">TASK2</span>' STO |
|||
The last task requirement takes too much time to be run on a calculator. On a emulator, we had to split it into 10 runs to not wake up the watchdog timer. |
|||
<span style="color:blue">TASK1</span> |
|||
# 987654321d '<span style="color:green">STATE</span>' STO |
|||
{ 5 } O CON |
|||
<span style="color:blue">TASK2</span> <span style="color:blue">TASK2</span> .. <span style="color:blue">TASK2</span> <span style="color:grey">@ 10 times</span> |
|||
{{out}} |
|||
<pre> |
|||
6: # 6457827717110365317d |
|||
5: # 3203168211198807973d |
|||
4: # 9817491932198370423d |
|||
3: # 4593380528125082431d |
|||
2: # 16408922859458223821d |
|||
1: [ 20027 19892 20073 19978 20030 ] |
|||
</pre> |
</pre> |
||
Line 1,397: | Line 1,443: | ||
{0=>20027, 1=>19892, 2=>20073, 3=>19978, 4=>20030} |
{0=>20027, 1=>19892, 2=>20073, 3=>19978, 4=>20030} |
||
</pre> |
</pre> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
{{trans|Perl}} |
{{trans|Perl}} |