Hello,(adsbygoogle = window.adsbygoogle || []).push({});

I'm currently writing a program for my computational physics course and ran into this issue with my program.

The function in matlab rand(1,1) gives you a random number from [0,1) to 4 significant figures. So for example if I ran this function it would look something like this.

input:

A = rand(1,1)

output:

A = .5040

Now I have to use this function to make it randomly choose beetween 3 objects (A,B,C). The problem I run into is that the professor told us to specifically use rand(1,1) for the random pick (Probably to test our math and get more familiar with the program.) Since this produces 10 possible values, then I need to assign (A,B,C) 10/3 apart.

Object_A = [.0000:.3333]

Object_B = (.3334:.6666)

Object_C = (.6667:.9999)

I set the object_pick = (rand(1,1))

possible values are (.0000-.9999)

then just write a bunch of if/else statements to determine which range of values the object_pick value falls.

Does this approach make sense to you guys from a mathematical point of view? Since the function rand(1,1) in matlab gives you a psuedorandom number as opposed to a truly randomly generated value as in C++, I feel that this method should be acceptable.

Any feedback, comments, or suggestions are much appreciated. Also, Thanks in to whoever took the time to read this.

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab question (possibly only a simple math problem)

**Physics Forums | Science Articles, Homework Help, Discussion**