Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[SheetWorker] Math.Random randomness

I keep seeing people talk about Math.random not being truly "random".  Since 2015, it looks like Chrome and Firefox (Chome v8 and SpiderMonkey engines) switched to the xorshift algorithm.  I couldn't find any information on what algorithm Chakra uses. In practice, I'm not finding anything that would make Math.random (at least in Chrome & Firefox) insufficient for generating dice rolls.  It may not match Roll20's QuantumRoll system, but the results meet the 3 criteria for random numbers (full-period, equi-distribution, unpredictibility). I'm parsing out dice rolls using the following regex:     // [\d]*d[\dFf]+[\!]? Standard syntax, FATE, Exploding // (?:(?=[Kk][\d]+)[Kk][\d]+|(?![Kk][\d]+)) keep dice // (?:(?=\[[^\]]+[\]])\[[^\]]+[\]]|(?!\[[^\]]+[\]])) Roll Tags static RegExp = /[\d]*d[\dFf]+[\!]?(?:(?=[Kk][\d]+)[Kk][\d]+|(?![Kk][\d]+))(?:(?=\[[^\]]+[\]])\[[^\]]+[\]]|(?!\[[^\]]+[\]]))/g So far in my tests it matches with a limited version of the roll syntax that Roll20 uses. 3d6!+2dF+3d8[Bludgeoning]+3d6!k1+7-1 returned all the correct matches, and using Math.random, seemingly random results (apparently uniform distribution at 10,000 iterations on each roll portion). So what what are the flaws for using Math.random on sheetworkers in FF and Chrome (possibly Edge, but Microsoft is a closed-source butt-munch about Chakra)? (Any advice on the regex patter would be appreciated, but that's a separate issue)
1540927835

Edited 1540929022
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The Math.random used in API scripts (note, not in sheetworkers) is not actually the standard Javascript Math.random. It uses the quantum roll engine instead of the default algorithm for Math.random. See the wiki for full details . EDIT: Realized you are talking about sheetworkers. The sheetworker Math.random is the standard javascript Math.random. It may certainly work fine, but it won't be as random as quantum roll. EDIT the second: Got some clarification on this; the two Math.random()'s (API vs. sheetworker) are the same, but are not powered by quantum roll. They are instead powered by the backup RNG, which is better than normal, but not up to quantum roll standards.
So Roll20 injects their own version of Math.random?  Is there any documentation on the underlying algorithm it uses?
1540930084
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I don't think so. It is the same RNG that was used prior to QuantumRoll (and is still used when quantum roll fails).
Well, it will have to do, I guess.  I can't imagine Roll20's implementation of Math.random would be less effective than the updated Math.random current browsers use.