Search code examples
randomeiffel

How to generate a random Integer between two values in Eiffel?


I want to simulate dice roll functionality. However, I don't get what I expect. I want to get a Dice with value ranging from 1 to 6 inclusively (dice).

I tried to find it in Eiffel Documentation, but it is very hard to do.


Solution

  • The following code prints values for 10 consecutive rolls:

    local
        r: RANDOM
    do
        across
            1 |..| 10 as i
        from
            create r.set_seed (...) -- ... is the initial "seed"
            r.start
        loop
            io.put_integer (r.item \\ 6 + 1)
            io.put_new_line
            r.forth
        end
    end