Linear congruential generator: Difference between revisions
Content added Content deleted
Simple9371 (talk | contribs) m (→{{header|Batch}}: Batch -> Batch File) |
Simple9371 (talk | contribs) m (→{{header|Scheme}}: Fix) |
||
Line 3,245: | Line 3,245: | ||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
For R7RS Scheme. |
|||
{{incomplete|Scheme|Precise which Scheme implementation and version you are using and which Report on the Algorithmic Language |
|||
<syntaxhighlight lang="scheme">(import (scheme base) |
|||
Scheme version it supports. Due to the implicit function generator definition, this works in Racket, but not in standards-compliant Scheme.}} |
|||
(scheme write)) |
|||
⚫ | |||
(define ((bsd-rand state)) |
|||
⚫ | |||
⚫ | |||
state) |
|||
⚫ | |||
⚫ | |||
(quotient state 65536)) |
|||
; auxiliary function to get a list of 'n random numbers from generator 'r |
; auxiliary function to get a list of 'n random numbers from generator 'r |
||
(define (rand-list r n |
(define (rand-list r n) |
||
(if (zero? n) '() (cons (r) (rand-list r (- n 1))))) |
|||
(rand-list (bsd-rand 0) 10) |
(display (rand-list (bsd-rand 0) 10)) |
||
; (12345 1406932606 654583775 1449466924 229283573 1109335178 1051550459 1293799192 794471793 551188310) |
; (12345 1406932606 654583775 1449466924 229283573 1109335178 1051550459 1293799192 794471793 551188310) |
||
(newline) |
|||
⚫ | |||
(display (rand-list (msvcrt-rand 0) 10)) |
|||
; (38 7719 21238 2437 8855 11797 8365 32285 10450 30612)</syntaxhighlight> |
; (38 7719 21238 2437 8855 11797 8365 32285 10450 30612)</syntaxhighlight> |
||