-
-
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.
- Loading branch information
Showing
8 changed files
with
63 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Fortuna | ||
The quick solution for everything random! | ||
|
||
A Gacha-like system to roll random items with weights. | ||
|
||
|
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 |
---|---|---|
@@ -1,6 +1,16 @@ | ||
{ | ||
"tasks": { | ||
"bench": "deno bench --unstable benches/comparison.ts", | ||
"test": "deno test test.ts" | ||
"bench": { | ||
"files": { | ||
"include": [ | ||
"./benches/comparison.ts" | ||
] | ||
} | ||
}, | ||
"test": { | ||
"files": { | ||
"include": [ | ||
"./test.ts" | ||
] | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,10 @@ | ||
// deno-fmt-ignore-file | ||
// deno-lint-ignore-file | ||
// This code was bundled using `deno bundle` and it's not recommended to edit it manually | ||
|
||
function unbiasedCoin(n = 1) { | ||
const upperBound = 1 << n; | ||
const res = Math.floor(Math.random() * upperBound).toString(2).padStart(n, "0"); | ||
return res.split("").map((x)=>x === "0" ? "H" : "T"); | ||
} | ||
export { unbiasedCoin as unbiasedCoin }; |
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,12 @@ | ||
// A biased coin can be implemented using GachaMachine. | ||
|
||
/** | ||
* Toss n unbiased coins (50% chance of head / tail). | ||
* @param n Number of coins to toss. | ||
* @returns Array of results. Returns "H" for head and "T" for tail. | ||
*/ | ||
export function unbiasedCoin(n = 1): ("H" | "T")[] { | ||
const upperBound = 1 << n | ||
const res = Math.floor(Math.random() * upperBound).toString(2).padStart(n, "0") | ||
return res.split("").map(x => x === "0" ? "H" : "T") | ||
} |
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