1 // Random (enough) string for socket and game IDs
2 export function getRandString()
4 return (Date
.now().toString(36) + Math
.random().toString(36).substr(2, 7))
8 export function random (min
, max
)
15 return Math
.floor(Math
.random() * (max
- min
) ) + min
;
18 // Inspired by https://github.com/jashkenas/underscore/blob/master/underscore.js
19 export function sample (arr
, n
)
22 let cpArr
= arr
.map(e
=> e
);
23 for (let index
= 0; index
< n
; index
++)
25 const rand
= getRandInt(index
, n
);
26 const temp
= cpArr
[index
];
27 cpArr
[index
] = cpArr
[rand
];
30 return cpArr
.slice(0, n
);
33 export function shuffle(arr
)
35 return sample(arr
, arr
.length
);