From 0d53a6ccde3e1a7517cd405593f9a3d633ac0aad Mon Sep 17 00:00:00 2001 From: Cory Sanin Date: Wed, 15 Oct 2025 00:24:59 -0500 Subject: [PATCH] replace Math.random() with crypto.randomInt() --- src/sequencer.ts | 3 ++- test/sequencer.test.ts | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sequencer.ts b/src/sequencer.ts index d9d5482..31dcb2e 100644 --- a/src/sequencer.ts +++ b/src/sequencer.ts @@ -2,6 +2,7 @@ import { OpenWeatherAPI, type DailyWeather } from 'openweather-api-node'; import { voiceLines } from './voice.js'; import type { Config } from './index.js'; import type { Voice } from './voice.js'; +import crypto from 'crypto'; type SegmentName = string; type SequenceName = string; @@ -16,7 +17,7 @@ type Sequences = { [sequence: SequenceName]: Sequence }; let config: Config = null; function selectOne(arr: T[]): T { - return arr[Math.floor(Math.random() * arr.length)]; + return arr[crypto.randomInt(0, arr.length)]; } function resolveSide(side: string, currentWeather: DailyWeather) { diff --git a/test/sequencer.test.ts b/test/sequencer.test.ts index 60187c6..d50c54a 100644 --- a/test/sequencer.test.ts +++ b/test/sequencer.test.ts @@ -1,7 +1,6 @@ import { describe, expect, it, vi } from 'vitest'; -import { type CurrentWeather, type Options } from 'openweather-api-node'; +import { type Options } from 'openweather-api-node'; import { Sequencer } from '../src/sequencer.js'; -import type { Config } from '../src/index.js'; const dummyWeather: Options = { key: 'dummy' };