Jump to content
Toggle menu
  • 3.1K articles
  • 4.4K files
  • 18 users
  • 91.5K edits
Ashenzari's Archive
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Random2: Difference between revisions

From Ashenzari's Archive
imported>CommanderC
No edit summary
imported>Ge0ff
Expand a bit
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''random2''' is a function used in Crawl's code to select a random number. It seems to be defined in the following way:
'''random2''' is a function used in Crawl's code to select a random number. It is defined in the following way:


'''random2(''int max'')'''
<code>random2(''int max'')</code>


and returns a random number from 0 to ''max-1''. Therefore, '''random2(2)''' returns either 0 or 1, which is how the '''[[coinflip]]''' function is defined.
and returns a random number from 0 to ''max-1'', which is <code>1d''max'' - 1</code> in the dice notation. Therefore, '''random2(2)''' returns either 0 or 1, which is how the '''coinflip''' function is defined.


'''random2''' is defined in [http://git.develz.org/?p=crawl.git;a=blob;f=crawl-ref/source/random.cc random.cc], along with many other important random functions. Most calculations of damage, quantities, and properties, will use it, so wiki editors who are looking into the source to find out these values should familiarise themself with the function.
'''random2''' is defined in [https://github.com/crawl/crawl/blob/master/crawl-ref/source/random.cc random.cc], along with many other important random functions. Most calculations of damage, quantities, and properties, will use it, so wiki editors who are looking into the source to find out these values should familiarise themself with the function.


[[Category:Source]]
[[Category:Source]]

Latest revision as of 17:12, 5 January 2022

random2 is a function used in Crawl's code to select a random number. It is defined in the following way:

random2(int max)

and returns a random number from 0 to max-1, which is 1dmax - 1 in the dice notation. Therefore, random2(2) returns either 0 or 1, which is how the coinflip function is defined.

random2 is defined in random.cc, along with many other important random functions. Most calculations of damage, quantities, and properties, will use it, so wiki editors who are looking into the source to find out these values should familiarise themself with the function.