Talk:Subtractive generator: Difference between revisions

mod is not really an operator; the formula is a congruence.
(mod is not really an operator; the formula is a congruence.)
Line 8:
:Neither is a big deal. mod is normally assumed to have a very low precedence, watch how TeX spaces this: <math>a-b\mod m</math>. And mod is most often assumed to operate on a positive m and produce a positive result, so <math>r_n</math> should be positive after the modulus anyway. --[[User:Ledrug|Ledrug]] 01:17, 5 August 2011 (UTC)
:: Not sure about that C, Java, Icon, and others have mod operators with the same precedence as multiplication and division. Also, several of these will return negative numbers. Anyway it is just clearer to document it with extra (). --[[User:Dgamey|Dgamey]] 06:01, 5 August 2011 (UTC)
 
:::I first wrote the formula as
:::* <math>r_n = r_{n - i} - r_{n - j} \pmod m</math>
:::but I feared that readers would confuse it with
:::* <math>r_n = r_n - i - r_n - j \pmod m</math>
:::so I added some extra parens. Dgamey suggested to add yet more parens.
 
:::''mod'' is not really an operator. The formula is a ''congruence'' that says the left side and the right side would have equal remainders. For example, if we had
:::* <math>r_n = 39 - 9 \pmod 100</math>
::: then <math>r_n</math> can be 30, or -70, or 130, or 42000030, because all of those integers are congruent (mod 100) to 39 - 9. In the task, I buried the phrase "uniform random integers from 0 to m - 1". This was my attempt to pick from the many congruent integers. --[[User:Kernigh|Kernigh]] 03:34, 7 August 2011 (UTC)
 
== So... what am I doing wrong? ==
Anonymous user