Pseudo-random numbers/Middle-square method: Difference between revisions
Content added Content deleted
(Pseudo-random numbers/Middle-square method in BASIC256 and Yabasic) |
(RPL: add section) |
||
Line 1,002: | Line 1,002: | ||
432883 |
432883 |
||
</pre> |
</pre> |
||
=={{header|RPL}}== |
|||
{{works with|Halcyon Calc|4.2.7}} |
|||
{| class="wikitable" |
|||
! RPL code |
|||
! Comment |
|||
|- |
|||
| |
|||
≪ |
|||
SQ →STR |
|||
'''WHILE''' DUP SIZE 12 ≠ '''REPEAT''' |
|||
"0" SWAP + '''END''' |
|||
4 9 SUB STR→ |
|||
≫ ‘'''RMID'''’ STO |
|||
≪ 675248 1 5 '''START RMID NEXT''' |
|||
≫ ‘'''TASK'''’ STO |
|||
| |
|||
'''RMID''' ''( seed -- seed )'' |
|||
var s = str(seed * seed) |
|||
do while not len(s) = 12 |
|||
s = "0" + s end do |
|||
seed = val(mid(s, 4, 6)) |
|||
return seed |
|||
|} |
|||
{{out}} |
|||
<pre> |
|||
5: 959861 |
|||
4: 333139 |
|||
3: 981593 |
|||
2: 524817 |
|||
1: 432883 |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
<syntaxhighlight lang="ruby">def middle_square (seed) |
<syntaxhighlight lang="ruby">def middle_square (seed) |