classes ACG binomial lognormal repick MCellRan4 discunif negexp seq MLCG erlang normal uniform Random123 geometric play weibull Random123_globalindex hypergeo poissonRandom
Random()
Random(seed)
Random(seed, size)
This class is an interface to the RNG class from the gnu c++ class library. As of version 5.2, a cryptographic quality RNG class wrapper for mcell_ran4 was added and is available with the MCellRan4 method. The current default random generator is ACG .
As of version 7.3, a more versatile cryptographic quality generator, Random123, is available with the Random123 method. This generator uses a 34bit counter, 2 32 bit identifiers, and a 32 bit global index and is most suitable for managing separate independent, reproducible, restartable streams that are unique to individual cell and synapses in large parallel network models. See: http://www.thesalmons.org/john/random123/papers/random123sc11.pdf
Note that multiple instances of the Random class will produce different streams of random numbers only if their seeds are different.
One can switch distributions at any time but if the distribution is stationary then it is more efficient to use r.repick() to avoid constructor/destructor overhead.
prints 20 random numbers ranging in value between 30 and 50.objref r r = new Random() for i=1,10 print r.uniform(30, 50) // not as efficient as for i=1,10 print r.repick() // this
Random
r.ACG()
r.ACG(seed)
r.ACG(seed, size)
Random
r.MLCG()
r.MLCG(seed1)
r.MLCG(seed1, seed2)
Random
highindex = r.MCellRan4()
highindex = r.MCellRan4(highindex)
highindex = r.MCellRan4(highindex, lowindex)
Note that for reproducibility, the distribution should be defined AFTER setting the seed since some distributions, such as normal , hold state information from a previous pick from the uniform distribution.
objref r, vec, g1, g2, hist r = new Random() index = r.MCellRan4() r.uniform(0, 2) vec = new Vector(1000) g1 = new Graph() g2 = new Graph() g1.size(0, 1000, 0, 2) g2.size(0, 2, 0, 150) proc doit() { g1.erase() g2.erase() vec.setrand(r) hist = vec.histogram(0, 2, 0.2) vec.line(g1) hist.line(g2, .2) g1.flush g2.flush } doit() variable_domain(&index, 0, 2^32-1) xpanel("MCellRan4 test") xbutton("Sample", "doit()") xpvalue("Original index", &index, 1, "r.MCellRan4(index) doit()") xpanel()
Random0 = r.Random123(id1, id2)
The generators should be usable in the context of threads as long as no instance is used in more than one thread.
This generator uses a 34bit counter, 2 32 bit identifiers, and a 32 bit global index and is most suitable for managing separate independent, reproducible, restartable streams that are unique to individual cell and synapses in large parallel network models. See: http://www.thesalmons.org/john/random123/papers/random123sc11.pdf
Randomuint32 = r.Random123_globalindex([uint32])
Randomcurrenthighindex = r.seq() r.seq(sethighindex)
For Random123, Gets and sets the counter value which ranges from 0 to 2^34-1. The reason the the greater range is that the internal Random123 generators return 4 uint32 values on each call. So that is done only every 4 picks from the generator.
objref r r = new Random() //r.uniform(0,1) r.negexp(1) //r.normal(0,1) mcell_ran4_init(1) r.MCellRan4(1) for i=0, 10 print i, r.repick r.MCellRan4(1) for i=0, 5 print i, r.repick idum = r.seq print "idum = ", idum for i=6, 10 print i, r.repick print "restarting" r.seq(idum) for i=6, 10 print i, r.repick print "restarting" r.seq(idum) for i=6, 10 print i, r.repick
Random
r.repick()
Random
r.play(&var)
(but with no interpreter overhead). This is similar in concept to play . Play may be called several times for different variables and each variable will get an independent random value but with the same distribution. To disconnect the Random object from its list of variables, either the variables or the Random object must be destroyed.var = r.repick()
// run the single script // use the PointProcessManager to select IClamp // set dur of IClamp[0] to 100 // open a new Voltage Graph objref r r = new Random() r.poisson(.01) r.play(&IClamp[0].amp) //open a RunControl // press Init&Run several times
Random
r.uniform(low, high)
objref r, vec, g1, g2, hist r = new Random() r.uniform(0, 2) vec = new Vector(1000) vec.setrand(r) hist = vec.histogram(0, 2, 0.2) g1 = new Graph() g2 = new Graph() g1.size(0, 1000, 0, 2) g2.size(0, 2, 0, 150) vec.plot(g1) hist.plot(g2, .2)
Random
r.discunif(low, high)
Random
r.normal(mean, variance)
objref r, g, hist, vec r = new Random() r.normal(-1, .5) vec = new Vector() vec.indgen(-3, 2, .1) // x-axis for plot hist = new Vector(vec.size()) g = new Graph() g.size(-3, 2, 0, 50) hist.plot(g, vec) for(i=0; i<500; i=i+1){ x = r.repick() print i, x j = int((x+3)*10) // -3 to 2 -> 0 to 50 if (j >= 0) { hist.x[j] = hist.x[j]+1 } g.flush() doNotify() }
Random
r.lognormal(mean, variance)
objref r, g, hist, xvec r = new Random() r.lognormal(5,2) n=20 xvec = new Vector(n*3) // bins look like discrete spikes for i=0,n-1 { xvec.x[3*i] = i-.1 xvec.x[3*i+1] = i xvec.x[3*i+2] = i+.1 } hist = new Vector(xvec.size()) g = new Graph() g.size(0, 15, 0, 120) hist.plot(g, xvec) for(i=0; i<500; i=i+1){ x = r.repick() print i, x j = int(x) j = 3*j+1 if (j >= hist.size()) { // don't let any off the edge j = hist.size() -1 } hist.x[j] = hist.x[j]+1 g.flush() doNotify() }
Random
r.poisson(mean)
objref r, g, hist, xvec r = new Random() r.poisson(3) n=20 xvec = new Vector(n*3) for i=0,n-1 { xvec.x[3*i] = i-.1 xvec.x[3*i+1] = i xvec.x[3*i+2] = i+.1 } hist = new Vector(xvec.size()) g = new Graph() g.size(0, 15, 0, 120) hist.plot(g, xvec) for(i=0; i<500; i=i+1){ x = r.repick() print i, x j = int(x) j = 3*j+1 if (j >= hist.size()) { j = hist.size() -1 } hist.x[j] = hist.x[j]+1 g.flush() doNotify() }
Random
r.binomial(N,p)
P(n, N, p) = p * P(n-1, N-1, p) + (1 - p) * P(n, N-1, p)
objref r, hist, g r = new Random() r.binomial(20, .5) g = new Graph() g.size(0, 20, 0, 100) hist = new Vector(20) hist.plot(g) for(i=0; i<500; i=i+1){ j = r.repick() hist.x[j] = hist.x[j]+1 g.flush() doNotify() }
Random
r.geometric(mean)
objref r, hist, g r = new Random() r.geometric(.8) hist = new Vector(1000) proc sample() { hist = new Vector(1000) hist.setrand(r) hist = hist.histogram(0,100,1) hist.plot(g) } g = new Graph() g.size(0,40,0,200) sample() xpanel("Resample") xbutton("Resample", "sample()") xpanel()
Random
r.hypergeo(mean,variance)
Random
r.negexp(mean)
objref r, hist, g r = new Random() r.negexp(2.5) hist = new Vector(1000) proc sample() { hist = new Vector(1000) hist.setrand(r) hist = hist.histogram(0,20,.1) hist.plot(g, .1) } g = new Graph() g.size(0,20,0,50) sample() xpanel("Resample") xbutton("Resample", "sample()") xpanel()
Random
r.erlang(mean,variance)
Random
r.weibull(alpha,beta)