LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I generate a random integer from 1-5?

Solved!
Go to solution
 If I use random how do I convert it to an integer?
Message 1 of 26
(72,756 Views)

check out the conversion palette under "Numeric->conversion"

 

untitled.GIF

Regards
Guru (CLA)
0 Kudos
Message 2 of 26
(72,745 Views)

For a Random Interger from 1 to 5 you do something like this:

 

1-5 Random.JPG

Edit: I just realised, that the chances for every Number are not the same, so my version is kind of unusable for statistically correct purposes.

Its too early in the morning 😉

Edit2: Also I realise further, that my version won't output 1-5 but 0-5 so it is not even what you wanted. D**n what did I do 😄

 

Cheers

Message Edited by Pattos on 01-20-2010 01:17 AM
Message Edited by Pattos on 01-20-2010 01:21 AM
Pattos

LabVIEW Gretchin
Message 3 of 26
(72,744 Views)
Could you just use a +1 increment after the multiplication? What does the I32 do exactly?
Message 4 of 26
(72,736 Views)
Solution
Accepted by Laudie3a

Alana wrote:
What does the I32 do exactly?

"To I32" converts your floating point number to an integer, as you specified in your first post as requirement. 😉

 

Here' a version that gives all 5 numbers with equal probability. Instead of explicitely converting to I32, I use the output configuration of the +1. Same difference. 😉

 

 

Message Edited by altenbach on 01-19-2010 11:39 PM
Message 5 of 26
(72,726 Views)

dear altenbach,

 

just some "additional" inputs to make it configurable... please kindly comment and advise. Thanks!

 

LVVILIB_NUM_integer random number generation.PNG  

Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
Message 6 of 26
(72,710 Views)

A similar one here 

Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 7 of 26
(72,680 Views)

Wouldn't you have to multiply times 4 vs 5. If the random number give you a one then you would get 5 and add 1 to it giving you 6.

 

 

Example.png

Tim
GHSP
0 Kudos
Message 8 of 26
(72,651 Views)

Wouldn't you have to multiply times 4 vs 5. If the random number give you a one then you would get 5 and add 1 to it giving you 6.

 

 

Example.png

Tim
GHSP
0 Kudos
Message 9 of 26
(72,649 Views)

No aestet, Altenbachs solution is perfectly fine.

 

The dice generate a Number between 0 and 1 (Not including 1!!) Multiplied by 5 that is a Number between 0 and 4.999999.

The next triangle always rounds the Number down, so that you can only get 0,1,2,3 and 4 everything with equal propablity.

Plus one you get 1,2,3,4 and 5. 

 

Pattos

LabVIEW Gretchin
Message 10 of 26
(72,643 Views)