# LabVIEW

Showing results for
Did you mean:

Solved!

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

If I use random how do I convert it to an integer?
Message 1 of 20 (30,877 Views)

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

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

Regards
Guru (CLA)
Message 2 of 20 (30,866 Views)

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

[ Edited ]

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

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 20 (30,865 Views)

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

Could you just use a +1 increment after the multiplication? What does the I32 do exactly?
Message 4 of 20 (30,857 Views)
Solution
Accepted by topic author Laudie3a
‎08-27-2015 06:09 PM

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

[ Edited ]

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 20 (30,847 Views)

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

dear altenbach,

Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010

LVVILIB.blogspot.com
Message 6 of 20 (30,831 Views)

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

A similar one here

Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010

LVVILIB.blogspot.com
Message 7 of 20 (30,803 Views)

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

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.

Tim
Yanfeng, Global Automotive Interiors
Holland Michigan
Message 8 of 20 (30,774 Views)

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

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.

Tim
Yanfeng, Global Automotive Interiors
Holland Michigan
Message 9 of 20 (30,772 Views)

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

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 20 (30,766 Views)