LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

random numbers - simulate a dice

Hello,

i found that "random number 0-1" feature in Labview, but how about
simulating a dice (1-6).

Best regards
f.pöck

0 Kudos
Message 1 of 19
(12,435 Views)

Hi

That's just simple math:

Let's say x is a random value.

So you get dice = 1 + round(x*5)

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 2 of 19
(12,417 Views)
Try the attachment.In the select tool true condition give your choice of number for to avoid getting zero.
 
by,
Kumar
0 Kudos
Message 3 of 19
(12,415 Views)

Just multiply by 6 and round to the next highest integer.

Choose the output that you want for your needs, integer or double.

Random is strictly between 0 and 1, but you might possibly want to make sure that rounding errors in the multiply haven't made the answer 7.

 

Rod.

 

 

Message Edited by Rod on 08-10-2006 12:16 PM

0 Kudos
Message 4 of 19
(12,409 Views)
Hey,
One more method, only if your are not particular about 64 bit Float (dbl) data representation of random number generated
0 Kudos
Message 5 of 19
(12,408 Views)

Errm, but if you multiply by 5 and convert the result to an integer, doesn't that give you a fencepost error??

Depending whether your conversion is to the integer above, below, or nearest you'd get no instances of 1, no instances of 6, or get 1 and 6 half as often as 2, 3, 4, or 5.

Rod.

 

0 Kudos
Message 6 of 19
(12,394 Views)
Yes Rod, that will also be a concern
0 Kudos
Message 7 of 19
(12,386 Views)


@F. Pöck wrote:
Hello,

i found that "random number 0-1" feature in Labview, but how about
simulating a dice (1-6).

Best regards
f.pöck



If you multiply by 6, round down and add 1 you get the required result.

The attached VI (LV7.0) shows that the distribution is even between the 6 numbers.

Tim Norris

"...and all this science I don't understand
it's just my job five days a week"


Using 6i, 7.0 & 7.1 on Win'98, 2K & XP
0 Kudos
Message 8 of 19
(12,343 Views)

See the attached example for multiple dice rolls simulated

 

Paul

LV 7.0

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 9 of 19
(12,325 Views)

Oops no attachment, here you go!

 

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 10 of 19
(12,324 Views)