UNPKG

arx-level-generator

Version:
43 lines (42 loc) 1.67 kB
export declare const randomSort: <T>(items: T[]) => T[]; /** * const values = pickWeightedRandoms(10, [ * { value: -6, weight: 10 }, * { value: 0, weight: 100 }, * { value: 6, weight: 10 }, * ]) * * values === [ * { value: 0, weight: 100 }, * { value: -6, weight: 10 }, * { value: 0, weight: 100 }, * { value: 0, weight: 100 }, * { value: 0, weight: 100 }, * { value: 6, weight: 10 }, * { value: 0, weight: 100 }, * { value: 0, weight: 100 }, * { value: 0, weight: 100 }, * { value: 0, weight: 100 } * ] * * guaranteePresenceOfAll=true will sort items with smaller weights to the beginning of the weightedSet * so they will always be present in the list of items, no matter how heavy other items are * this way the item with weight=1 will be guaranteed to show up in the selected list */ export declare const pickWeightedRandoms: <T extends Record<string, any>>(amount: number, set: (T & { weight: number; })[], guaranteePresenceOfAll?: boolean) => (T & { weight: number; })[]; /** * creates a random floating point number between a (inclusive) and b (exclusive) */ export declare const randomBetween: (a: number, b: number) => number; /** * creates a random integer between min and max (both inclusive) * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#getting_a_random_integer_between_two_values_inclusive */ export declare const randomIntBetween: (min: number, max: number) => number; export declare const pickRandoms: <T>(n: number, set: T[]) => T[]; export declare const pickRandom: <T>(set: T[]) => T; export declare const pickRandomIdx: <T>(set: T[]) => number;