On Wed, Nov 18, 2015 at 2:28 PM, Stefan Karpinski <[email protected]> wrote: > Sometimes you've looked at your own code too long to see these things. > Someone else sees it right away.
Disclaimer, I didn't see it right away either before running your code. > > On Wed, Nov 18, 2015 at 2:04 PM, Michele Zaffalon > <[email protected]> wrote: >> >> >> >> On Wed, Nov 18, 2015 at 5:43 PM, Yichao Yu <[email protected]> wrote: >>> >>> On Wed, Nov 18, 2015 at 11:37 AM, Michele Zaffalon >>> <[email protected]> wrote: >>> > Hi all, >>> > >>> > I would be glad if somebody could explain to me why the following >>> > function >>> > which generates a pair of random integer between 1 and 6 and if they >>> > are >>> > equal generates another pair >>> > >>> > function fun() >>> > d, N = 6, 50 >>> > for n = 1:N >>> > a, b = rand(1:d), rand(1:d) >>> > if a == b >>> > c, d = rand(1:d), rand(1:d) >>> >>> You realize you are overriding d to a smaller and smaller number until >>> you end up always calling rand(1:1) right? >> >> >> This is very very embarrassing. >> >>> >>> > println("$a, $b, $c, $d") >>> > end >>> > end >>> > end >>> > >>> > >>> > under Windows 7 64 bits and Julia 0.4.1 returns mostly 1s. >>> > >>> > julia> fun() >>> > 1, 1, 3, 3 >>> > 3, 3, 3, 2 >>> > 2, 2, 2, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > 1, 1, 1, 1 >>> > >>> > For small N, the output is more random though. >>> > >>> > Thank you, >>> > michele >> >> >
