Use randomInt for randomWord

This commit is contained in:
Jonas Lochmann 2022-09-19 02:00:00 +02:00
parent c82d3a4657
commit d8bed91dbc
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36

View file

@ -15,6 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { randomInt } from 'crypto'
import { readFileSync } from 'fs' import { readFileSync } from 'fs'
import { range } from 'lodash' import { range } from 'lodash'
import { resolve } from 'path' import { resolve } from 'path'
@ -24,7 +25,7 @@ const wordlist = readFileSync(resolve(__dirname, '../../other/wordlist/de.txt'))
.split('\n') .split('\n')
.filter((item) => item.trim().length > 0) .filter((item) => item.trim().length > 0)
const randomWord = () => wordlist[Math.floor(Math.random() * (wordlist.length - 1))] const randomWord = () => wordlist[randomInt(wordlist.length)]
export const randomWords = (numberOfWords: number) => ( export const randomWords = (numberOfWords: number) => (
range(numberOfWords) range(numberOfWords)