Cancel
Showing results for 
Search instead for 
Did you mean: 

random value from table

Creator
Creator

Hi all,

 

I have a simple problem, which I cannot solve.

I have four variables in a method and need to assign each variable a value between 0 and 9.

The Sum off all four variables need to be equal to 9.

I then save the results in a table and repeat it for 100 times (How to save the values in the tables is no problem) It is important that all numbers from 0 to 9 are eqaully distributed for EACH variable. This is the crux. Can anybody help me?

 

Im very pleased for any solution.

Thank you very much.

Regards, Ben

5 REPLIES

Re: random value from table

Siemens Phenom Siemens Phenom
Siemens Phenom

Hello Benedikt,

 

use z_uniform(1, 0.0, 1.0) to generate 4 real random numbers between 0.0 and 1.0. Calculate the value f by dividing 9.0 through the sum of your 4 random numbers. Then multiply each number by the value f.

Regards,

Ralf
------------------------------------------------------------------------------------------------------
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.

Re: random value from table

Siemens Phenom Siemens Phenom
Siemens Phenom

Just one additional remark: You won't get an equal distribution for each variable between 0 and 9. Since the constraint that the sum has to be 9 favours smaller numbers.

Regards,

Ralf
------------------------------------------------------------------------------------------------------
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.

Re: random value from table

Creator
Creator

Thanks. That idea works.

 

Unfortunately I really need the equal distribution

I am working on a different solution right now but struggeling at the following:

Is there a way to chose randomly between four (self determined) parameters that I have saved in a table {1,1}..{4,1} and adress them in a method?

 

Regards,

Ben

Re: random value from table

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor
try z_dEmp
Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net

Re: random value from table

Creator
Creator

Thanks.

 

I found, what I needed.

 

Regards,

Ben