forked from tgstation/TerraGov-Marine-Corps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tgui part of tgstation/tgstation#67691 and tgstation/tgstation#66971
- Loading branch information
1 parent
e702688
commit 0e65c9f
Showing
6 changed files
with
146 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { clamp } from "./math"; | ||
|
||
/** | ||
* Returns random number between lowerBound exclusive and upperBound inclusive | ||
*/ | ||
export const randomNumber = (lowerBound: number, upperBound: number) => { | ||
return Math.random() * (upperBound - lowerBound) + lowerBound; | ||
}; | ||
|
||
/** | ||
* Returns random integer between lowerBound exclusive and upperBound inclusive | ||
*/ | ||
export const randomInteger = (lowerBound: number, upperBound: number) => { | ||
lowerBound = Math.ceil(lowerBound); | ||
upperBound = Math.floor(upperBound); | ||
return Math.floor(Math.random() * (upperBound - lowerBound) + lowerBound); | ||
}; | ||
|
||
/** | ||
* Returns random array element | ||
*/ | ||
export const randomPick = <T>(array: T[]) => { | ||
return array[Math.floor(Math.random() * array.length)]; | ||
}; | ||
|
||
/** | ||
* Return 1 with probability P percent; otherwise 0 | ||
*/ | ||
export const randomProb = (probability: number) => { | ||
const normalized = clamp(probability, 0, 100)/100; | ||
return Math.random() <= normalized; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters