/***********************************************************
crnd.c -- 線形合同法
***********************************************************/

Dim seed = 1 As DWord/* 任意 */

Sub init_rnd(x As DWord)
seed = x
End Sub


Function irnd() As DWord
seed = seed * 1566083941 As DWord + 1
irnd = seed
End Function

Function rnd() As Double /* 0 <= rnd() < 1 */
rnd = (1 / 4294967296) * irnd() As Double
End Function

/**********************************************************/
#N88BASIC
Dim i As Long
init_rnd(12345) /* 任意の DWord で初期化. 省略可. */
For i= 0 To 159
Print rnd(),
Next