Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Random number generator ====== The RNG object is available as ''salet.rnd''. Unlike ''Math.random'', Salet's version of RNG is predictable: the generator gives the same numbers when initialized with the same seed value. That's why it won't change the result after saving and loading the game. The generator produces pseudo-random numbers with a perion of 2³². That should be enough for most games. The ''multiplier'', ''modulo'', ''offset'' properties are system RNG properties. If you don't know what they are, you probably shouldn't change them. ===== CoffeeScript properties ===== ==== modulo ==== 2³² - 1 value. ===== CoffeeScript methods ===== ==== randn ==== Returns a pseudorandom integer number bigger or equal to ''0'' and less than ''[[#modulo]]'' ==== randf ==== Returns a pseudorandom floating point number bigger or equal to ''0'' and less than ''1''. ==== rand ==== Returns a pseudorandom integer number bigger or equal to ''0'' and less than ''n'' **Argument:** a number ''n'', any number ==== randomInt ==== An alias for [[#rand]] method. ==== randomElement ==== Returns a random element from the supplied array. **Argument:** an array of elements. ==== randRange ==== Returns a pseudorandom integer number bigger or equal to ''min'' and less than ''max''. The number will be integer if ''min'' is integer too. **Argument 1:** a number ''min'', any number **Argument 2:** a number ''max'', any number ==== dice ==== Returns a result of throwing ''n'' dice which have ''dx'' faces each. The ''plus'' value is added to the result. **Argument 1:** ''n'' - integer number\\ **Argument 2:** ''dx'' - integer number **Argument 3:** ''plus'' - a number, optional argument ==== diceString ==== Returns a result of throwing ''n'' dice which have ''dx'' faces each. The ''plus'' value is added to the result. This method accepts one argument instead of three: a string in the form of ''NdX+plus''. By default, ''plus = 0'', ''n = 1'' In addition to the usual number of faces, this method also understands cubes ''dF'' - the so-called "fudge dice", and ''d%'' - a percentage cube d100. **Argument 1:** a string like ''NdX+plus'' ==== odds ==== Returns a chance in percents of the ''value +'' the value that would be on a dice with ''n'' faces would be greater than the ''target'' value. **Argument 1:** ''value'' - initial value **Argument 2:** ''target'' - target value **Argument 3:** ''n'' - amount of dice faces ==== seed ==== The initial seed that initializes the generator. By default, Salet uses current time (with millisecond precision) **Argument:** integer value that should be much less than ''[[#modulo]]'' ==== getSeed ==== The method that returns the ''[[#seed]]'' value. {{tag>api}} en/api/rng.txt Last modified: 2021/01/24 10:42by 127.0.0.1