10 examples of 'mdn math.random' in JavaScript

Every line of 'mdn math.random' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
51function random (n){
52 if(typeof n === 'object'){
53 var times = n[1]-n[0];
54 var offset = n[0];
55 return Math.random()*times + offset;
56 }else{
57 return n;
58 }
59}
78public static random(): number {
79 return math.random();
80}
30function rand( n ) {
31 return n * randu();
32}
648static Random (n, m) {
649 return new Matrix.Zero(n, m).map(
650 function() { return Math.random(); }
651 );
652}
29function randn(mu, std) { return mu + gaussRandom() * std; }
107function randn(rng: () => number, mu: number, std: number) {
108 return mu + gaussRandom(rng) * std;
109};
1export function random(d, type) {
2 const a = new Array(d);
3
4 for (let i = 0; i < d; i++) {
5 a[i] = type(Math.floor(Math.random() * d));
6 }
7
8 return a;
9}
7function generate_n(rng: RandomGenerator, num: number): [number[], RandomGenerator] {
8 let cur: RandomGenerator = rng;
9 const out: number[] = [];
10 for (let idx = 0 ; idx != num ; ++idx) {
11 const [value, next] = cur.next();
12 out.push(value);
13 cur = next;
14 }
15 return [out, cur];
16}
218export function randn(mu: number, std: number): number {
219 return mu + Util.gaussRandom() * std;
220}
313function pseudorandom(nMax) {
314 seed = (seed + 0.81282849124) * 2375.238208308;
315 seed -= Math.floor(seed);
316
317 return Math.floor(seed * nMax);
318};

Related snippets