Question

I just start to study about Octave and I have a question about getting Rational Numbers.

I just check

http://www.gnu.org/software/octave/doc/interpreter/Random-Number-Generation.html#Random-Number-Generation

this page to learn the way to get random Rational Numbers. for example..

if we use rand(1, 3.1)

i would like to get random number between 1 and 3.1 (like 2.34)

However, i am not really sure about function that i have to use..

can you give some example ?

thanks

Was it helpful?

Solution

The function unifrnd returns random numbers sampled from a uniform distribution. The first two arguments determine the lower and upper bounds. The remaining (optional) arguments determine the shape of the result. So, for example, to get random numbers between 1 and 3.1:

octave:12> unifrnd(1, 3.1)
ans =  2.4990
octave:13> unifrnd(1, 3.1)
ans =  3.0240
octave:14> unifrnd(1, 3.1, 2, 3)
ans =

   1.8929   2.9675   2.1239
   2.4756   2.6172   1.6197

(The results are regular floating point numbers. I don't understand why you are asking about rational numbers.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top