On Wed, Nov 18, 2015 at 11:37 AM, Michele Zaffalon
<michele.zaffa...@gmail.com> 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?

>             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

Reply via email to