1 // Random (enough) string for socket and game IDs
2 export function getRandString() {
4 Date
.now().toString(36) +
11 export function randInt(min
, max
) {
16 return Math
.floor(Math
.random() * (max
- min
)) + min
;
19 // Inspired by https://github.com/jashkenas/underscore
20 export function sample(arr
, n
) {
22 let cpArr
= arr
.map(e
=> e
);
23 for (let index
= 0; index
< n
; index
++) {
24 const rand
= randInt(index
, arr
.length
);
25 [ cpArr
[index
], cpArr
[rand
] ] = [ cpArr
[rand
], cpArr
[index
] ];
27 return cpArr
.slice(0, n
);
30 export function shuffle(arr
) {
31 return sample(arr
, arr
.length
);