-
Notifications
You must be signed in to change notification settings - Fork 0
/
random.js
138 lines (110 loc) · 4.06 KB
/
random.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
export const __name__ = 'random';
export const __doc__ = `
Random variable generators.
integers
--------
uniform within range
sequences
---------
pick random element
pick random sample
pick weighted random sample
generate random permutation
distributions on the real line:
------------------------------
uniform
triangular
normal (Gaussian)
lognormal
negative exponential
gamma
beta
pareto
Weibull
distributions on the circle (angles 0 to 2pi)
---------------------------------------------
circular uniform
von Mises
General notes on the underlying Mersenne Twister core generator:
* The period is 2**19937-1.
* It is one of the most extensively tested generators in existence.
* The random() method is implemented in js, executes in a single Python step,
and is, therefore, threadsafe.
`;
//*Bookkeeping Functions:
export const seed = (a = null, version = 2) => {};
export const getstate = () => {};
export const setstate = state => {};
export const getrandbits = k => {};
//* Functions for integers:
export const randrange = function(start, stop = null, step = 1, _int = Number) {
// Need Adjustments!!________________________________________
if (String(start).includes('.') || String(stop).includes('.'))
return TypeError('Requires an integer recieved float');
let place = Number('1' + '0'.repeat(String(stop).length));
let ints = [];
for (let i = start; i < stop; i += step)
ints.push(i);
let indx = Math.floor(Math.random() * place);
return indx < ints.length ? ints[indx] : randint(start, stop);
};
export const randint = (a, b) => randrange(a, b + 1);
//* Functions for sequences:
export const choice = seq => seq[Math.floor(Math.random() * seq.length)];
export const choices = (population, weights = null, cum_weights = null, k = 1) => {};
export const shuffle = (x, random = null) => {};
export const sample = (population, k) => {};
//* Real-valued Distributions:
export const random = Math.random;
export const uniform = (a, b) => {};
export const triangular = (low, high, mod) => {};
export const betavariate = (alpha, beta) => {};
export const expovariate = lambda => {};
export const gammavariate = (alpha, beta) => {};
export const gauss = (mu, sigma) => {};
export const lognormvariate = (mu, sigma) => {};
export const normalvariate = (mu, sigma) => {};
export const vonmisesvariate = (mu, kappa) => {};
export const paretovariate = alpha => {};
export const weibullvariate = (alpha, beta) => {};
//* Alternative Generator:
export class Random { constructor(seed = null) {} }
export class SystemRandom { constructor(seed = null) {} }
/*
*___________Out of use yet!_______________
export const BPF = function() {};
export const LOG4 = function() {};
export const NV_MAGICCONST = function() {};
export const RECIP_BPF = function() {};
export const SG_MAGICCONST = function() {};
export const TWOPI = function() {};
export const _Sequence = function() {};
export const _Set = function() {};
export const __all__ = function() {};
export const __builtins__ = function() {};
export const __cached__ = function() {};
export const __file__ = function() {};
export const __loader__ = function() {};
export const __package__ = function() {};
export const __spec__ = function() {};
export const _accumulate = function() {};
export const _acos = Math.acos;
export const _bisect = function() {};
export const _ceil = Math.ceil;
export const _cos = Math.cos;
export const _e = Math.E;
export const _exp = Math.exp;
export const _inst = function() {};
export const _log = Math.log;
export const _os = function() {};
export const _pi = Math.PI;
export const _random = Math.random;
export const _repeat = function() {};
export const _sha512 = function() {};
export const _sin = Math.sin;
export const _sqrt = Math.sqrt;
export const _test = function() {};
export const _test_generator = function() {};
export const _urandom = function() {};
export const _warn = function() {};
*/