Showing results for 
Search instead for 
Did you mean: 
Reply

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

Solved!
Go to Solution

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

 If I use random how do I convert it to an integer?
0 Kudos
Message 1 of 20 (25,444 Views)
Reply
0 Kudos

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

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

 

untitled.GIF

Regards
Guru (CLA)
0 Kudos
Message 2 of 20 (25,433 Views)
Reply
0 Kudos

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:

 

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 Smiley Wink

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 Smiley Very Happy

 

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
0 Kudos
Message 3 of 20 (25,432 Views)
Reply
0 Kudos

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?
0 Kudos
Message 4 of 20 (25,424 Views)
Reply
0 Kudos
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. Smiley Wink

 

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. Smiley Wink

 

 

Message Edited by altenbach on 01-19-2010 11:39 PM
Message 5 of 20 (25,414 Views)

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

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
依恩与LabVIEW
LVVILIB.blogspot.com
Message 6 of 20 (25,398 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
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 7 of 20 (25,370 Views)
Reply
0 Kudos

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.

 

 

Example.png

Tim
Yanfeng, Global Automotive Interiors
Holland Michigan
0 Kudos
Message 8 of 20 (25,341 Views)
Reply
0 Kudos

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.

 

 

Example.png

Tim
Yanfeng, Global Automotive Interiors
Holland Michigan
0 Kudos
Message 9 of 20 (25,339 Views)
Reply
0 Kudos

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
0 Kudos
Message 10 of 20 (25,333 Views)
Reply
0 Kudos