9ff11593586a0a099d64f95ba919a91dfb4236ec
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/blob/master/underscore.js
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 const temp
= cpArr
[index
];
26 cpArr
[index
] = cpArr
[rand
];
29 return cpArr
.slice(0, n
);
32 export function shuffle(arr
) {
33 return sample(arr
, arr
.length
);