Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export function randomExclude( min: number , max: number , excludeList: number[] ): number {
- console.log( `randomExclude( ${min}, ${max} , [${excludeList}] )` );
- // (złożoność lg n, tablica exclude musi być wcześniej posortowana).
- excludeList = excludeList.sort();
- // losujesz liczbę od min do max-len(exclude)
- let value: number = random( min , ( max - excludeList.length ) );
- //sprawdzasz, ile jest liczb w exclude mniejszych od wylosowanej (złożoność lg n, tablica exclude musi być wcześniej posortowana).
- excludeList.forEach( (n: number) => {
- if ( n < value ) {
- //dodajesz do wylosowanej liczby tę wartość
- value += 1;
- }
- } );
- console.log( `value = ${value}` );
- return value;
- }
Advertisement
Add Comment
Please, Sign In to add comment