random number generator #268

Parent #1Owner #361Flags readSource hellcore/hellcore.db

Aliases: random number generator

5 verbs · 10 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
make_statethis none thisrxd#2682
randomthis none thisrxd#2688
gilthis none thisrxd#26811
testthis none thisrxd#2689
test2this none thisrxd#26810

Properties

PropertyDefinerFlagsOwnerValue
aliases#1rc#361{"random number generator"}
description#1rc#361<clear>
object_size#1r#29{2771, 1298434541}
hidden_verbs#1rc#361<clear>
phelp_msg#1rc#361<clear>
weight#1rc#361<clear>
owner_verbs#1rc#361<clear>
plural_name#1rc#361<clear>
client_image#1rc#361<clear>
listening#1rc#361<clear>

Ancestry

Ancestors (nearest first): #1 root

Children: none

Call graph

calls n268_3 #268:test n107_43 #107:tell n268_3->n107_43 n268_4 #268:test2 n268_4->n107_43

Source

make_state

Spec this none thisFlags rxdOwner #361Definer #268

Referenced by

Source

1":make_state(seed) => Make a random-state from 'seed', which must be an integer.";
2return args[1] || 1;

random

Spec this none thisFlags rxdOwner #361Definer #268

Referenced by

Source

1":random(max, state) => Return a two-element list consisting of a random number between 1 and 'max' and a new random-state.";
2{max, state} = args;
3"FIXME: This is a terrible algorithm, don't use for anything important.  Should be a Mersenne Twister.";
4a = 16807;
5c = 0;
6m = $maxint;
7val = mod((a * state) + c, m);
8return {mod(val, max) + 1, val};

gil

Spec this none thisFlags rxdOwner #361Definer #268

Referenced by

Source

1"Given a max and a seed, return an int from 1 to max corresponding to the seed. f(seed) = ???";
2{max, seed} = args;
3seed = toint(seed);
4r = seed + 447217;
5save = ((r / 10) % 10) + 1;
6r = r % (max * 10);
7r = r + 191;
8r = r * 93169;
9r = r + 17;
10r = (r % (max * save)) / save;
11return r + 1;

test

Spec this none thisFlags rxdOwner #361Definer #268

Referenced by

none

Source

1vname = args[1];
2max = (length(args) > 1) ? args[2] | 100;
3total = 0;
4for x in [1..100]
5val = this:(vname)(max, x);
6player:tell(x, " => ", val);
7total = total + val;
8endfor
9player:tell("Avg: ", total / 100);

test2

Spec this none thisFlags rxdOwner #361Definer #268

Referenced by

none

Source

1vname = args[1];
2max = (length(args) > 1) ? args[2] | 100;
3total = 0;
4for who in (players()[$ - 50..$])
5x = toint(who);
6val = this:(vname)(max, x);
7player:tell(x, " => ", val);
8total = total + val;
9endfor
10player:tell("Avg: ", total / 50);