ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

random modification

How can i modify a random number? let's say, that i want a random number between 1 and 100, and i want it to be an integer? thx
oh.. i am using LabVIEW 6.1
 
0 Kudos
Message 1 of 5
(4,680 Views)
Hi,

create a random number (Numeric Palette -> Random Number). That ranges from 0 to 1. Multiply it by 99. This will range from 0-99. Then add 1. The result will be in the range of 1-100 as you requested. Then round to integer (Numeric Palette -> Round to Nearest).

Regards
Matthias

Message Edited by matthias.richwin on 02-12-2007 10:54 AM

0 Kudos
Message 2 of 5
(4,675 Views)
The method Matthias suggests would have the problem that both 1 and 100 have half the probability of the other numbers appearing. (The float numbers are equally probable between 1 and 100; but only 1.0 to 1.5 will give 1, then 1.5 to 2.5 gives 2, ... and finally 99.5 to 100.0 gives 100)
 
I would multiply by the random number by 100.0, giving 0.0 to 100.0, (excluding 0 and 100) then round to + infinity, ie the nearest integer above, giving 1 to 100.
 
You might possibly want to check that rounding errors on the multiply haven't resulted in the rounding up giving 101.
 
Rod.
 
Message 3 of 5
(4,650 Views)
Right, Rod. Yours is even more simple, and of course more accurate.

Regards
Matthias
0 Kudos
Message 4 of 5
(4,646 Views)

I would like to say thx for all your help, you really were in great help!

I am new at this program, so i might ask some more n00b questions 😛

Thx again!

0 Kudos
Message 5 of 5
(4,628 Views)