Seven-sided dice from five-sided dice: Difference between revisions

m
syntax highlighting fixup automation
(Added solution for Free Pascal (Lazarus))
m (syntax highlighting fixup automation)
Line 19:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F dice5()
R random:(1..5)
 
Line 36:
 
distcheck(dice5, 1000000, 1)
distcheck(dice7, 1000000, 1)</langsyntaxhighlight>
 
{{out}}
Line 46:
=={{header|Ada}}==
The specification of a package Random_57:
<langsyntaxhighlight Adalang="ada">package Random_57 is
 
type Mod_7 is mod 7;
Line 55:
-- a simple implementation
 
end Random_57;</langsyntaxhighlight>
Implementation of Random_57:
<langsyntaxhighlight Adalang="ada"> with Ada.Numerics.Discrete_Random;
 
package body Random_57 is
Line 113:
begin
Rand_5.Reset(Gen);
end Random_57;</langsyntaxhighlight>
A main program, using the Random_57 package:
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO, Random_57;
 
procedure R57 is
Line 165:
Test( 1_000_000, Rand'Access, 0.02);
Test(10_000_000, Rand'Access, 0.01);
end R57;</langsyntaxhighlight>
{{out}}
<pre>
Line 198:
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d]}}
C's version using no multiplications, divisions, or mod operators:
<langsyntaxhighlight lang="algol68">PROC dice5 = INT:
1 + ENTIER (5*random);
 
Line 232:
distcheck(dice5, 1000000, 5);
distcheck(dice7, 1000000, 7)
)</langsyntaxhighlight>
{{out}}
<pre>
Line 240:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">dice5()
{ Random, v, 1, 5
Return, v
Line 250:
IfLess v, 21, Return, (v // 3) + 1
}
}</langsyntaxhighlight>
<pre>Distribution check:
 
Line 267:
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> MAXRND = 7
FOR r% = 2 TO 5
check% = FNdistcheck(FNdice7, 10^r%, 0.1)
Line 297:
IF bins%(i%)/(repet%/m%) < 1-delta s% += 1
NEXT
= s%</langsyntaxhighlight>
{{out}}
<pre>
Line 307:
 
=={{header|C}}==
<langsyntaxhighlight lang="c">int rand5()
{
int r, rand_max = RAND_MAX - (RAND_MAX % 5);
Line 326:
printf(check(rand7, 7, 1000000, .05) ? "flat\n" : "not flat\n");
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>
Line 335:
=={{header|C sharp}}==
{{trans|Java}}
<langsyntaxhighlight lang="csharp">
using System;
 
Line 361:
return 1 + random.Next(5);
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
This solution tries to minimize calls to the underlying d5 by reusing information from earlier calls.
<langsyntaxhighlight lang="cpp">template<typename F> class fivetoseven
{
public:
Line 413:
test_distribution(d5, 1000000, 0.001);
test_distribution(d7, 1000000, 0.001);
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
Uses the verify function defined in [[Verify distribution uniformity/Naive#Clojure]]
<langsyntaxhighlight Clojurelang="clojure">(def dice5 #(rand-int 5))
 
(defn dice7 []
Line 431:
(doseq [n [100 1000 10000] [num count okay?] (verify dice7 n)]
(println "Saw" num count "times:"
(if okay? "that's" " not") "acceptable"))</langsyntaxhighlight>
 
<pre>Saw 0 10 times: not acceptable
Line 457:
=={{header|Common Lisp}}==
{{trans|C}}
<langsyntaxhighlight lang="lisp">(defun d5 ()
(1+ (random 5)))
 
Line 463:
(loop for d55 = (+ (* 5 (d5)) (d5) -6)
until (< d55 21)
finally (return (1+ (mod d55 7)))))</langsyntaxhighlight>
 
<pre>> (check-distribution 'd7 1000)
Line 479:
=={{header|D}}==
{{trans|C++}}
<langsyntaxhighlight lang="d">import std.random;
import verify_distribution_uniformity_naive: distCheck;
 
Line 525:
distCheck(&fiveToSevenNaive, N, 1);
distCheck(&fiveToSevenSmart, N, 1);
}</langsyntaxhighlight>
{{out}}
<pre>1 80365
Line 552:
{{trans|Common Lisp}}
{{improve|E|Write dice7 in a prettier fashion and use the distribution checker once it's been written.}}
<langsyntaxhighlight lang="e">def dice5() {
return entropy.nextInt(5) + 1
}
Line 560:
while ((d55 := 5 * dice5() + dice5() - 6) >= 21) {}
return d55 %% 7 + 1
}</langsyntaxhighlight>
<langsyntaxhighlight lang="e">def bins := ([0] * 7).diverge()
for x in 1..1000 {
bins[dice7() - 1] += 1
}
println(bins.snapshot())</langsyntaxhighlight>
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">defmodule Dice do
def dice5, do: :rand.uniform( 5 )
Line 585:
IO.inspect VerifyDistribution.naive( fun5, 1000000, 3 )
fun7 = fn -> Dice.dice7 end
IO.inspect VerifyDistribution.naive( fun7, 1000000, 3 )</langsyntaxhighlight>
 
{{out}}
Line 594:
 
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">
<lang Erlang>
-module( dice ).
 
Line 611:
dice7_small_enough( N ) when N < 21 -> N div 3 + 1;
dice7_small_enough( _N ) -> dice7().
</syntaxhighlight>
</lang>
 
{{out}}
Line 620:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: kernel random sequences assocs locals sorting prettyprint
math math.functions math.statistics math.vectors math.ranges ;
IN: rosetta-code.dice7
Line 676:
{ 1 10 100 1000 10000 100000 1000000 }
[| times | 0.02 7 [ dice7 ] times verify ] each
;</langsyntaxhighlight>
 
{{out}}
Line 697:
=={{header|Forth}}==
{{works with|GNU Forth}}
<langsyntaxhighlight lang="forth">require random.fs
 
: d5 5 random 1+ ;
Line 703:
: d7
begin d5 d5 2dup discard? while 2drop repeat
1- 5 * + 1- 7 mod 1+ ;</langsyntaxhighlight>
{{out}}
<pre>cr ' d7 1000000 7 1 check-distribution .
Line 718:
=={{header|Fortran}}==
{{works with|Fortran|95 and later}}
<langsyntaxhighlight lang="fortran">module rand_mod
implicit none
 
Line 754:
call distcheck(rand7, samples, 0.001)
 
end program</langsyntaxhighlight>
{{out}}
<pre>Distribution Uniform
Line 769:
=={{header|FreeBASIC}}==
{{trans|Liberty BASIC}}
<langsyntaxhighlight lang="freebasic">
Function dice5() As Integer
Return Int(Rnd * 5) + 1
Line 786:
If Not(distCheck(n, 0.05)) Then Print "Test failed" Else Print "Test passed"
Sleep
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 793:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 848:
max, flatEnough = distCheck(dice7, 7, calls, 500)
fmt.Println("Max delta:", max, "Flat enough:", flatEnough)
}</langsyntaxhighlight>
{{out}}
<pre>
Line 856:
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">random = new Random()
 
int rand5() {
Line 868:
}
(raw % 7) + 1
}</langsyntaxhighlight>
Test:
<langsyntaxhighlight lang="groovy">def test = {
(1..6). each {
def counts = [0g, 0g, 0g, 0g, 0g, 0g, 0g]
Line 895:
=============="""
test(it)
}</langsyntaxhighlight>
{{out}}
<pre style="height:30ex;overflow:scroll;">TRIAL #1
Line 1,005:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import System.Random
import Data.List
 
Line 1,013:
let d7 = 5*d51+d52-6
if d7 > 20 then sevenFrom5Dice
else return $ 1 + d7 `mod` 7</langsyntaxhighlight>
{{out}}
<langsyntaxhighlight lang="haskell">*Main> replicateM 10 sevenFrom5Dice
[2,3,1,1,6,2,5,6,5,3]</langsyntaxhighlight>
Test:
<langsyntaxhighlight lang="haskell">*Main> mapM_ print .sort =<< distribCheck sevenFrom5Dice 1000000 3
(1,(142759,True))
(2,(143078,True))
Line 1,025:
(5,(142896,True))
(6,(143028,True))
(7,(143130,True))</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
{{trans|Ruby}}
Uses <code>verify_uniform</code> from [[Simple_Random_Distribution_Checker#Icon_and_Unicon|here]].
<syntaxhighlight lang="icon">
<lang Icon>
$include "distribution-checker.icn"
 
Line 1,046:
else write ("skewed")
end
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,062:
=={{header|J}}==
The first step is to create 7-sided dice rolls from 5-sided dice rolls (<code>rollD5</code>):
<langsyntaxhighlight lang="j">rollD5=: [: >: ] ?@$ 5: NB. makes a y shape array of 5s, "rolls" the array and increments.
roll2xD5=: [: rollD5 2 ,~ */ NB. rolls D5 twice for each desired D7 roll (y rows, 2 cols)
toBase10=: 5 #. <: NB. decrements and converts rows from base 5 to 10
Line 1,068:
groupin3s=: [: >. >: % 3: NB. increments, divides by 3 and takes ceiling
 
getD7=: groupin3s@keepGood@toBase10@roll2xD5</langsyntaxhighlight>
Here are a couple of variations on the theme that achieve the same result:
<langsyntaxhighlight lang="j">getD7b=: 0 8 -.~ 3 >.@%~ 5 #. [: <:@rollD5 2 ,~ ]
getD7c=: [: (#~ 7&>:) 3 >.@%~ [: 5&#.&.:<:@rollD5 ] , 2:</langsyntaxhighlight>
The trouble is that we probably don't have enough D7 rolls yet because we compressed out any double D5 rolls that evaluated to 21 or more. So we need to accumulate some more D7 rolls until we have enough. J has two types of verb definition - tacit (arguments not referenced) and explicit (more conventional function definitions) illustrated below:
 
Here's an explicit definition that accumulates rolls from <code>getD7</code>:
<langsyntaxhighlight lang="j">rollD7x=: monad define
n=. */y NB. product of vector y is total number of D7 rolls required
rolls=. '' NB. initialize empty noun rolls
Line 1,082:
end.
y $ rolls NB. shape the result according to the vector y
)</langsyntaxhighlight>
Here's a tacit definition that does the same thing:
<langsyntaxhighlight lang="j">getNumRolls=: [: >. 0.75 * */@[ NB. calc approx 3/4 of the required rolls
accumD7Rolls=: ] , getD7@getNumRolls NB. accumulates getD7 rolls
isNotEnough=: */@[ > #@] NB. checks if enough D7 rolls accumulated
 
rollD7t=: ] $ (accumD7Rolls ^: isNotEnough ^:_)&''</langsyntaxhighlight>
The <code>verb1 ^: verb2 ^:_</code> construct repeats <code>x verb1 y</code> while <code>x verb2 y</code> is true. It is like saying "Repeat accumD7Rolls while isNotEnough".
 
Example usage:
<langsyntaxhighlight lang="j"> rollD7t 10 NB. 10 rolls of D7
6 4 5 1 4 2 4 5 2 5
rollD7t 2 5 NB. 2 by 5 array of D7 rolls
Line 1,110:
1
($@rollD7x -: $@rollD7t) 2 3 5
1</langsyntaxhighlight>
 
=={{header|Java}}==
{{trans|Python}}
<langsyntaxhighlight Javalang="java">import java.util.Random;
public class SevenSidedDice
{
Line 1,134:
return 1+rnd.nextInt(5);
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
{{trans|Ruby}}
<langsyntaxhighlight lang="javascript">function dice5()
{
return 1 + Math.floor(5 * Math.random());
Line 1,155:
distcheck(dice5, 1000000);
print();
distcheck(dice7, 1000000);</langsyntaxhighlight>
{{out}}
<pre>1 199792
Line 1,172:
 
=={{header|Julia}}==
<langsyntaxhighlight Julialang="julia">dice5() = rand(1:5)
 
function dice7()
r = 5*dice5() + dice5() - 6
r < 21 ? (r%7 + 1) : dice7()
end</langsyntaxhighlight>
Distribution check:
<pre>julia> hist([dice5() for i=1:10^6])
Line 1,186:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1.3
 
import java.util.Random
Line 1,229:
fun main(args: Array<String>) {
checkDist(::dice7, 1_400_000)
}</langsyntaxhighlight>
 
Sample output:
Line 1,249:
 
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
<lang lb>
n=1000000 '1000000 would take several minutes
print "Testing ";n;" times"
Line 1,273:
dice5=1+int(rnd(0)*5) '1..5: dice5
end function
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 1,291:
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">dice5 = function() return math.random(5) end
 
function dice7()
Line 1,297:
if x > 20 then return dice7() end
return x%7 + 1
end</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
Line 1,303:
 
We check for uniform numbers using +-5% from expected value.
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Def long i, calls, max, min
Line 1,339:
}
CheckIt
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,366:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">sevenFrom5Dice := (tmp$ = 5*RandomInteger[{1, 5}] + RandomInteger[{1, 5}] - 6;
If [tmp$ < 21, 1 + Mod[tmp$ , 7], sevenFrom5Dice])</langsyntaxhighlight>
<pre>CheckDistribution[sevenFrom5Dice, 1000000, 5]
->Expected: 142857., Generated :{142206,142590,142650,142693,142730,143475,143656}
Line 1,374:
=={{header|Nim}}==
We use the distribution checker from task [[Simple Random Distribution Checker#Nim|Simple Random Distribution Checker]].
<langsyntaxhighlight Nimlang="nim">import random, tables
 
 
Line 1,409:
import random
randomize()
checkDist(dice7, 1_000_000, 0.5)</langsyntaxhighlight>
 
{{out}}
Line 1,417:
 
=={{header|OCaml}}==
<langsyntaxhighlight lang="ocaml">let dice5() = 1 + Random.int 5 ;;
 
let dice7 =
Line 1,433:
in
aux
;;</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="parigp">dice5()=random(5)+1;
 
dice7()={
Line 1,442:
while((t=dice5()*5+dice5()) > 21,);
(t+2)\3
};</langsyntaxhighlight>
 
=={{header|Pascal}}==
Line 1,450:
 
A chi-squared test can be carried out with the help of statistical tables, and is preferred here to an arbitrary "naive" test.
<langsyntaxhighlight lang="pascal">
unit UConverter;
(*
Line 1,589:
until false;
end.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,607:
=={{header|Perl}}==
Using dice5 twice to generate numbers in the range 0 to 24. If we consider these modulo 8 and re-call if we get zero, we have eliminated 4 cases and created the necessary number in the range from 1 to 7.
<langsyntaxhighlight lang="perl">sub dice5 { 1+int rand(5) }
 
sub dice7 {
Line 1,620:
$count7{dice7()}++ for 1..$n;
printf "%s: %5.2f%%\n", $_, 100*($count7{$_}/$n*7-1) for sort keys %count7;
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,634:
=={{header|Phix}}==
replace rand7() in [[Verify_distribution_uniformity/Naive#Phix]] with:
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">function</span> <span style="color: #000000;">dice5</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">rand</span><span style="color: #0000FF;">(</span><span style="color: #000000;">5</span><span style="color: #0000FF;">)</span>
Line 1,645:
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,652:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(de dice5 ()
(rand 1 5) )
 
Line 1,658:
(use R
(until (> 21 (setq R (+ (* 5 (dice5)) (dice5) -6))))
(inc (% R 7)) ) )</langsyntaxhighlight>
{{out}}
<pre>: (let R NIL
Line 1,667:
=={{header|PureBasic}}==
{{trans|Lua}}
<langsyntaxhighlight PureBasiclang="purebasic">Procedure dice5()
ProcedureReturn Random(4) + 1
EndProcedure
Line 1,680:
ProcedureReturn x % 7 + 1
EndProcedure</langsyntaxhighlight>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">from random import randint
 
def dice5():
Line 1,690:
def dice7():
r = dice5() + dice5() * 5 - 6
return (r % 7) + 1 if r < 21 else dice7()</langsyntaxhighlight>
Distribution check using [[Simple Random Distribution Checker#Python|Simple Random Distribution Checker]]:
<pre>>>> distcheck(dice5, 1000000, 1)
Line 1,699:
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ 5 random 1+ ] is dice5 ( --> n )
 
[ dice5 5 *
Line 1,710:
6 6 7 7 7 ]
dup 0 = iff
drop again ] is dice7 ( --> n )</langsyntaxhighlight>
 
{{out}}
Line 1,724:
=={{header|R}}==
5-sided die.
<langsyntaxhighlight lang="r">dice5 <- function(n=1) sample(5, n, replace=TRUE)</langsyntaxhighlight>
Simple but slow 7-sided die, using a while loop.
<langsyntaxhighlight lang="r">dice7.while <- function(n=1)
{
score <- numeric()
Line 1,736:
score
}
system.time(dice7.while(1e6)) # longer than 4 minutes</langsyntaxhighlight>
More complex, but much faster vectorised version.
<langsyntaxhighlight lang="r">dice7.vec <- function(n=1, checkLength=TRUE)
{
morethan2n <- 3 * n + 10 + (n %% 2) #need more than 2*n samples, because some are discarded
Line 1,755:
} else score
}
system.time(dice7.vec(1e6)) # ~1 sec</langsyntaxhighlight>
 
=={{header|Racket}}==
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket
(define (dice5) (add1 (random 5)))
Line 1,765:
(define res (+ (* 5 (dice5)) (dice5) -6))
(if (< res 21) (+ 1 (modulo res 7)) (dice7)))
</syntaxhighlight>
</lang>
 
Checking the uniformity using math library:
 
<langsyntaxhighlight lang="racket">
-> (require math/statistics)
-> (samples->hash (for/list ([i 700000]) (dice7)))
Line 1,779:
(2 . 99927)
(1 . 99622))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 1,785:
{{works with|Rakudo|2018.03}}
 
<syntaxhighlight lang="raku" perl6line>my $d5 = 1..5;
sub d5() { $d5.roll; } # 1d5
 
Line 1,804:
for @dist.kv -> $i, $v {
say "$i\t$v\t" ~ (($v - $expect)/$expect*100).fmt("%+.2f%%") if $v;
}</langsyntaxhighlight>
{{out}}
<pre>Expect 142857.143
Line 1,817:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX program simulates a 7─sided die based on a 5─sided throw for a number of trials. */
parse arg trials sample seed . /*obtain optional arguments from the CL*/
if trials=='' | trials="," then trials= 1 /*Not specified? Then use the default.*/
Line 1,838:
' difference from expected:'right(die.j - expect, length(sample) )
end /*j*/
end /*#*/ /*stick a fork in it, we're all done. */</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 11 </tt>}}
 
Line 1,945:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Seven-sided dice from five-sided dice
 
Line 1,965:
rnd = random(4) + 1
return rnd
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,974:
{{trans|Tcl}}
Uses <code>distcheck</code> from [[Simple_Random_Distribution_Checker#Ruby|here]].
<langsyntaxhighlight lang="ruby">require './distcheck.rb'
 
def d5
Line 1,988:
 
distcheck(1_000_000) {d5}
distcheck(1_000_000) {d7}</langsyntaxhighlight>
 
{{out}}
Line 2,006:
=={{header|Scala}}==
{{Out}}Best seen running in your browser either by [https://scalafiddle.io/sf/3RNtNEC/0 ScalaFiddle (ES aka JavaScript, non JVM)] or [https://scastie.scala-lang.org/Y5qSeW52QiC40l5vJCUMRA Scastie (remote JVM)].
<langsyntaxhighlight Scalalang="scala">import scala.util.Random
 
object SevenSidedDice extends App {
Line 2,022:
println("Random number from 1 to 7: " + seven)
 
}</langsyntaxhighlight>
 
=={{header|Sidef}}==
{{trans|Perl}}
<langsyntaxhighlight lang="ruby">func dice5 { 1 + 5.rand.int }
 
func dice7 {
Line 2,041:
count7.keys.sort.each { |k|
printf("%s: %5.2f%%\n", k, 100*(count7{k}/n * 7 - 1));
}</langsyntaxhighlight>
{{out}}
<pre>1: -0.00%
Line 2,053:
=={{header|Tcl}}==
Any old D&D hand will know these as a D5 and a D7...
<langsyntaxhighlight lang="tcl">proc D5 {} {expr {1 + int(5 * rand())}}
 
proc D7 {} {
Line 2,062:
}
}
}</langsyntaxhighlight>
Checking:
<span class="sy0">%</span> distcheck D5 <span class="nu0">1000000</span>
Line 2,071:
=={{header|VBA}}==
The original StackOverflow page doesn't exist any longer. Luckily [https://web.archive.org/web/20100730055051/http://stackoverflow.com:80/questions/137783/given-a-function-which-produces-a-random-integer-in-the-range-1-to-5-write-a-fun archive.org] exists.
<langsyntaxhighlight lang="vb">Private Function Test4DiscreteUniformDistribution(ObservationFrequencies() As Variant, Significance As Single) As Boolean
'Returns true if the observed frequencies pass the Pearson Chi-squared test at the required significance level.
Dim Total As Long, Ei As Long, i As Integer
Line 2,112:
Next i
Debug.Print "[1] ""Uniform? "; Test4DiscreteUniformDistribution(Bins, 0.05); """"
End Sub</langsyntaxhighlight>
{{out}}<pre>[1] "Data set:" 142418 142898 142940 142573 143030 143139 143002
Chi-squared test for given frequencies
Line 2,120:
 
=={{header|VBScript}}==
<langsyntaxhighlight lang="vb">Option Explicit
 
function dice5
Line 2,132:
loop until j < 21
dice7 = j mod 7 + 1
end function</langsyntaxhighlight>
 
=={{header|Verilog}}==
<langsyntaxhighlight lang="verilog">
 
///////////////////////////////////////////////////////////////////////////////
Line 2,259:
end
endmodule
</syntaxhighlight>
</lang>
 
Compiling with Icarus Verilog
Line 2,287:
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "random" for Random
import "/sort" for Sort
import "/fmt" for Fmt
Line 2,329:
}
 
checkDist.call(dice7, 1400000, 0.5)</langsyntaxhighlight>
 
{{out}}
Line 2,349:
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">var die5=(1).random.fp(6); // [1..5]
fcn die7{ while((r:=5*die5() + die5())>=27){} r/3-1 }
 
Line 2,360:
 
println("Looking for ",100.0/7,"%");
rtest(0d1_000_000);</langsyntaxhighlight>
{{out}}
<pre>
10,327

edits