To generate a random number from the interval [1,6], you can use the randi
function in Matlab. The randi
function generates a uniformly distributed pseudorandom integer between 1 and some specified value. You can use randi(6)
to generate a random integer between 1 and 6:
main.m71 chars2 lines
If you want to generate multiple random numbers, you can use a loop:
main.m226 chars6 lines
This script will generate 10 random numbers between 1 and 6 and display them in the command window.
gistlibby LogSnag