Writing a project in EiffelStudio that simulates a dice roll

56 Views Asked by At

I am attempting to simulate a dice roll using the RANDOM class in the BASE library. With my current code, it only ever prints out 5.

class
    APPLICATION

create
    make

feature
    make
        local
            random_obj: RANDOM
        do
            create random_obj.make
            io.put_integer (random_obj.next_random (random_obj.item) \\ 6 + 1)
        end

end
1

There are 1 best solutions below

0
On

You're always using the default seed. You need to set a different seed on each run.

create random_obj.set_seed (...)

The current time in seconds as an INTEGER_32 is a good option for a seed that will be different on each run.