Skip to content

Commit

Permalink
Fixing use of Math.random
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterBarclay committed Mar 16, 2024
1 parent 18a406d commit 02e3684
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion fission/src/components/MainHUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { usePanelControlContext } from "../PanelContext"
import { motion } from "framer-motion"
import logo from "../assets/autodesk_logo.png"
import { ToastType, useToastContext } from "../ToastContext"
import { Random } from "@/util/Random"

type ButtonProps = {
value: string
Expand Down Expand Up @@ -156,7 +157,7 @@ const MainHUD: React.FC = () => {
"info",
"warning",
"error",
][Math.floor(Math.random() * 3)] as ToastType
][Math.floor(Random() * 3)] as ToastType
addToast(
type,
type,
Expand Down
7 changes: 4 additions & 3 deletions fission/src/components/SelectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useCallback, useEffect, useRef, useState } from "react"
import Button, { ButtonSize } from "./Button"
import Label, { LabelSize } from "./Label"
import Stack, { StackDirection } from "./Stack"
import { Random } from '@/util/Random';

type SelectButtonProps = {
colorClass?: string
Expand All @@ -20,7 +21,7 @@ const SelectButton: React.FC<SelectButtonProps> = ({
}) => {
const [value, setValue] = useState<string>()
const [selecting, setSelecting] = useState<boolean>(false)
const timeoutRef = useRef<NodeJS.Timer>()
const timeoutRef = useRef<NodeJS.Timeout>()

const onReceiveSelection = useCallback(
(value: string) => {
Expand All @@ -40,12 +41,12 @@ const SelectButton: React.FC<SelectButtonProps> = ({
() => {
if (selecting) {
const v = `node_${Math.floor(
Math.random() * 10
Random() * 10
).toFixed(0)}`
onReceiveSelection(v)
}
},
Math.floor(Math.random() * 2_750) + 250
Math.floor(Random() * 2_750) + 250
)
}
}, [selecting, onReceiveSelection])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Button from "@/components/Button"
import Dropdown from "@/components/Dropdown"
import Modal, { ModalPropsImpl } from "@/components/Modal"
import Stack, { StackDirection } from "@/components/Stack"
import { Random } from "@/util/Random"
import { extend as cdExtend, random as cdRandom, colord } from "colord"
import a11yPlugin from "colord/plugins/a11y"
import React, { useState } from "react"
Expand Down Expand Up @@ -127,7 +128,7 @@ const ThemeEditorModal: React.FC<ModalPropsImpl> = ({ modalId }) => {
if (selectedTheme == initialThemeName) return;
const keys: ColorName[] = Object.keys(themes[selectedTheme]) as ColorName[];
keys.forEach(k => {
const randAlpha = () => Math.max(0.1, Math.random());
const randAlpha = () => Math.max(0.1, Random());
updateColor(selectedTheme, k, { ...cdRandom().toRgb(), a: randAlpha() } as RgbaColor);
})
applyTheme(selectedTheme)
Expand Down

0 comments on commit 02e3684

Please sign in to comment.