Random numbers: Difference between revisions

Content added Content deleted
m (moved to Common Lisp)
Line 296: Line 296:
collect (1+ (* (sqrt (* -2 (log (random 1.0)))) (cos (* 2 pi (random 1.0))) 0.5)))</lang>
collect (1+ (* (sqrt (* -2 (log (random 1.0)))) (cos (* 2 pi (random 1.0))) 0.5)))</lang>


=== Alternate solution ===
I use [https://franz.com/downloads/clp/survey Allegro CL 10.1]

<lang lisp>
;; Project : Random numbers
;; Date : 2018/03/05
;; Author : Gal Zsolt [~ CalmoSoft ~]
;; Email : <calmosoft@gmail.com

(format t "~a" "Random numbers between 1 and 9")
(dotimes (n 10)
(if (< n 1) (terpri))
(if (< n 9) (format t "~a" " "))
(write(+ n 1)) (format t "~a" ": ")
(write(+ 1 (random 9))) (terpri))
</lang>
Output:
<pre>
Random numbers between 1 and 9
1: 3
2: 1
3: 9
4: 9
5: 5
6: 7
7: 1
8: 7
9: 5
10: 7
</pre>
=={{header|D}}==
=={{header|D}}==
<lang d>import std.stdio, std.random, std.math;
<lang d>import std.stdio, std.random, std.math;
Line 1,072: Line 1,102:
a( i) =mean +sd *( sqr( -2 * log( rnd( 0))) * cos( 2 * pi * rnd( 0)))
a( i) =mean +sd *( sqr( -2 * log( rnd( 0))) * cos( 2 * pi * rnd( 0)))
next i</lang>
next i</lang>

=={{header|Lisp}}==

I use [https://franz.com/downloads/clp/survey Allegro CL 10.1]

<lang lisp>
;; Project : Random numbers
;; Date : 2018/03/05
;; Author : Gal Zsolt [~ CalmoSoft ~]
;; Email : <calmosoft@gmail.com

(format t "~a" "Random numbers between 1 and 9")
(dotimes (n 10)
(if (< n 1) (terpri))
(if (< n 9) (format t "~a" " "))
(write(+ n 1)) (format t "~a" ": ")
(write(+ 1 (random 9))) (terpri))
</lang>
Output:
<pre>
Random numbers between 1 and 9
1: 3
2: 1
3: 9
4: 9
5: 5
6: 7
7: 1
8: 7
9: 5
10: 7
</pre>


=={{header|Logo}}==
=={{header|Logo}}==