fixed hash shit
This commit is contained in:
parent
d1c7d4d0da
commit
0dca37f035
|
|
@ -3,21 +3,6 @@ export const pickRandom = <T>(arr: T[]) => {
|
||||||
return arr[index];
|
return arr[index];
|
||||||
};
|
};
|
||||||
|
|
||||||
function bashHashStr(str: string) {
|
|
||||||
let hash = 5381,
|
|
||||||
i = str.length;
|
|
||||||
|
|
||||||
while (i) {
|
|
||||||
hash = (hash * 33) ^ str.charCodeAt(--i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash >>> 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const hashStr = (str: string) => {
|
|
||||||
return Number(`0.${bashHashStr(str)}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const weightedPickRandom = <T>(
|
export const weightedPickRandom = <T>(
|
||||||
arr: T[],
|
arr: T[],
|
||||||
getWeight: (item: T) => number = () => 1,
|
getWeight: (item: T) => number = () => 1,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue