hello: Add safety assertions.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-05-30 10:14:27 -07:00
parent 94f0f9340c
commit 4e91572c96
1 changed files with 3 additions and 2 deletions

View File

@ -1,12 +1,13 @@
// Mark this as a module for ESLint and Webpack.
export {};
import assert from "minimalistic-assert";
function get_new_rand(old_random_int: number, max: number): number {
assert(max >= 2);
const random_int = Math.floor(Math.random() * max);
return random_int === old_random_int ? get_new_rand(random_int, max) : random_int;
}
function get_random_item_from_array<T>(array: T[]): T {
assert(array.length >= 1);
return array[Math.floor(Math.random() * array.length)];
}