How to generate random numbers in Octave
Generate random number
kodingwindow@kw:~$ octave
...
octave> rand(1)
ans = 0.7154

octave> rand(1)*10
ans = 8.7886

octave> rand(1)*100
ans = 78.646

octave> rand(1)*1000
ans = 387.05

octave> round(rand(1)*1000)
ans = 779
Generate random integer numbers
octave> randi(100)
ans = 21

octave> randi(1000)
ans = 848

octave> randi([10,15])
ans = 14

octave> randi([10,15])
ans = 10

octave> randi(5,5)
ans =

    1   1   4   5   1
    2   5   4   4   3
    2   4   3   2   3
    2   1   2   3   1
    3   5   5   3   2
Advertisement