Unbias a random generator: Difference between revisions

J: use name suggested in task description, and include some counts requested in task
(→‎{{header|Java}}: Marked incomplete as it doesn't adequately generate and show counts of the outputs of randN and unbiased(randN) over the range of N)
(J: use name suggested in task description, and include some counts requested in task)
Line 9:
 
=={{header|J}}==
 
{{incomplete|J|It doesn't adequately generate and show counts of the outputs of randN and unbiased(randN) over the range of N.}}
<lang j>biasedrandN=: 0 = ?
unbiased=: i.@# { ::$: 2 | 0 3 -.~ _2 #.\ 4&* biasedrandN@# ]</lang>
 
Example use:
 
<lang j> biasedrandN 10#6
1 0 0 0 1 0 0 0 0 0
unbiased 10#6
1 0 0 1 0 0 1 0 1 1</lang>
 
Some example counts (these are counts of the number of 1s which appear in a test involving 100 random numbers):
 
<lang j> +/randN 100#3
30
+/randN 100#4
20
+/randN 100#5
18
+/randN 100#6
18
+/unbiased 100#3
49
+/unbiased 100#4
46
+/unbiased 100#5
49
+/unbiased 100#6
47</lang>
 
Note that these results are random. For example, a re-run of +/randN 100#5 gave 25 as its result.
 
=={{header|Java}}==
6,962

edits