diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-03-28 00:06:16 +1100 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-03-28 00:06:16 +1100 |
| commit | e31a74ff9a71e59eb0cd87c13a38c0934965404c (patch) | |
| tree | 935bcbf639b1988c7ba1ed3cf584f4cce63f3119 /src/lib.ts | |
| parent | bdc3bf69fae2e61aed8b3e41f46d2b0675a88231 (diff) | |
Make auto-mode more uniformly random and avoid undoing previous actions
Diffstat (limited to 'src/lib.ts')
| -rw-r--r-- | src/lib.ts | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -849,8 +849,9 @@ export function updateAscSeq(seq: number[], maxLen: number){ } } } -// Given an array of positive weights, returns a array index chosen with weighted pseudorandomness -export function randWeightedChoice(weights: number[]){ +// Given a non-empty array of non-negative weights, returns an array index chosen with weighted pseudorandomness +// Returns null if array contains all zeros +export function randWeightedChoice(weights: number[]): number | null { let thresholds = Array(weights.length); let sum = 0; for (let i = 0; i < weights.length; i++){ @@ -863,4 +864,5 @@ export function randWeightedChoice(weights: number[]){ return i; } } + return null; } |
