Commit 0a097b5c authored by Russ Cox's avatar Russ Cox

change rand names to match type names

R=r
DELTA=66  (19 added, 9 deleted, 38 changed)
OCL=15232
CL=15265
parent 729bc5c0
......@@ -9,17 +9,11 @@
*/
package rand
/*
export
srand // set rand state (int32)
vrand // int64 63-bits
lrand // int32 31-bits
rand // int 15-bits
vnrand // int64 % (int64)
lnrand // int32 % (int32)
nrand // int % (int)
frand; // float64 >=0.0 <1.0
*/
// rand, rand31, rand63 - return non-negative random int, int32, int64
// urand32 - return random uint32
// nrand, nrand31, nrand63 - return 0 <= random < n
// frand, frand64, frand32 - return 0 <= random float, float64, float32 < 1
const
(
......@@ -84,7 +78,7 @@ srand(seed int32)
}
export func
vrand() int64
rand63() int64
{
rng_tap--;
if rng_tap < 0 {
......@@ -102,56 +96,72 @@ vrand() int64
}
export func
lrand() int32
urand32() uint32
{
x := vrand() & 0x7fffffff;
return int32(x);
return uint32(rand63() >> 31);
}
export func
rand() int
rand31() int32
{
x := vrand() & 0x7fff;
return int(x);
return int32(rand63() >> 32);
}
export func
vnrand(n int64) int64
rand() int
{
var v,slop int64;
u := uint(rand63());
return int(u << 1 >> 1); // clear sign bit if int == int32
}
slop = MASK % n;
for v = vrand(); v <= slop; v = vrand() {
export func
nrand63(n int64) int64
{
if n <= 0 {
return 0
}
return v % n;
max := int64((1<<63)-1 - (1<<63) % uint64(n));
v := rand63()
for v > max {
v = rand63()
}
return v % n
}
export func
lnrand(n int32) int32
nrand31(n int32) int32
{
v := vnrand(int64(n));
return int32(v);
return int32(nrand63(int64(n)))
}
export func
nrand(n int) int
{
v := vnrand(int64(n));
return int(v);
return int(nrand63(int64(n)))
}
export func
frand() float64
frand64() float64
{
var x float64;
x = float64(vrand()) / float64(MASK);
x := float64(rand63()) / float64(MASK);
for x >= 1 {
x = float64(vrand()) / float64(MASK);
}
x = float64(rand63()) / float64(MASK);
}
return x;
}
export func
frand32() float32
{
return float32(frand64())
}
export func
frand() float
{
return float(frand64())
}
func
init()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment