random number generator #268
Aliases: random number generator
5 verbs · 10 properties · 0 children
Verbs
| Verb | Spec | Flags | Definer | Lines |
|---|---|---|---|---|
make_state | this none this | rxd | #268 | 2 |
random | this none this | rxd | #268 | 8 |
gil | this none this | rxd | #268 | 11 |
test | this none this | rxd | #268 | 9 |
test2 | this none this | rxd | #268 | 10 |
Properties
| Property | Definer | Flags | Owner | Value |
|---|---|---|---|---|
aliases | #1 | rc | #361 | {"random number generator"} |
description | #1 | rc | #361 | <clear> |
object_size | #1 | r | #29 | {2771, 1298434541} |
hidden_verbs | #1 | rc | #361 | <clear> |
phelp_msg | #1 | rc | #361 | <clear> |
weight | #1 | rc | #361 | <clear> |
owner_verbs | #1 | rc | #361 | <clear> |
plural_name | #1 | rc | #361 | <clear> |
client_image | #1 | rc | #361 | <clear> |
listening | #1 | rc | #361 | <clear> |
Ancestry
Ancestors (nearest first): #1 root
Children: none
Call graph
Source
make_state
Referenced by
- #20:crapsum line 10:
$rng:make_state - #98:voice_of line 8:
$rng:make_state
Source
1":make_state(seed) => Make a random-state from 'seed', which must be an integer."; 2return args[1] || 1;
random
Referenced by
- #20:crapsum line 13:
$rng:random - #98:voice_of line 8:
$rng:random - #98:voice_of line 10:
$rng:random
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
Referenced by
- #307:forge_name line 44:
$rng:gil - #307:forge_name line 47:
$rng:gil
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
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
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);