[AM] (21 june 2007) I came across a relatively simple PRNG recommended by George Marsaglia, arguably an authority on the subject: # marsaglia.tcl -- # Implementation of a PRNG according to George Marsaglia # namespace eval ::PRNG { variable mod [expr {wide(256)*wide(256)*wide(256)*wide(256)-5}] variable fac [expr {wide(256)*wide(32)}] variable x1 [expr {wide($mod*rand())}] variable x2 [expr {wide($mod*rand())}] variable x3 [expr {wide($mod*rand())}] puts $mod } proc ::PRNG::marsaglia {} { variable mod variable fac variable x1 variable x2 variable x3 set xn [expr {($fac*($x3+$x2+$x1))%$mod}] set x1 $x2 set x2 $x3 set x3 $xn return [expr {$xn/double($mod)}] } # main -- # A small test # package require Tk package require Plotchart pack [canvas .c] set p [::Plotchart::createXYPlot .c {0 1 0.2} {0 1 0.2}] set x [::PRNG::marsaglia] $p dataconfig series -type symbol -symbol dot for {set i 0} {$i < 1000} {incr i} { set y [::PRNG::marsaglia] $p plot series $x $y set x $y } The implementation has a few disadvantages: using the builtin random number generator for seeding it means you only get 2**31 different series, but the run-length is about 2**92 for each series. [AM] (22 june 2007) I am thinking about a small package/module to make Monte Carlo simulations easy to do. Here is my first attempt at such simulations: [A simple Monte Carlo simulation] And here is a first attempt at a package that could be useful: # random.tcl -- # Create procedures that return various types of pseudo-random # number generators (PRNGs) # # math::random -- # Create the namespace # namespace eval ::math::random { variable count 0 variable pi [expr {4.0*atan(1.0)}] } # prng_Binomial -- # Create a PRNG with a binomial distribution # # Arguments: # p Probability that the outcome will be 1 # # Result: # Name of a procedure that returns a binomially distributed # random number # proc ::math::random::prng_Binomial {p} { variable count incr count set name ::math::random::PRNG_$count proc $name {} [string map [list P $p] {return [expr {rand()