Cart | Help
 You are here: NI Home > NI Developer Zone > NI Discussion Forums Select Community English Français Italiano 日本語 한국어 Español 简体中文 繁体中文 Português (BR)

Member
Posts: 54

# random number with upper limit

I need this:

I need generate a random number with labview but tthis number must be less than 45. In vi  attached I do these, butusing a case estructure in the false case when random number no is lees than 45, i no get a number,  i get zero; but i dont want this, i need other number, i could used a string and write other number for default, but i will use after other  random number too lees than 45 and this must be different tan the other, two random number must be diferrent

how could generate the above?

Help me...

See a VI atacched

Knight of NI
Posts: 16,091

# Re: random number with upper limit

Why would you code require more than a random number (0-1) multiplied by 45?

Ben

Ben Rayner
Who is NOT John Galt... yet... just building Rayner's Ridge

Knight of NI
Posts: 22,798

# Re: random number with upper limit

You are making several mistakes, for example the random number generator belongs inside the loop, else it will execute only once at the start of the program and you always get the same number during the loop. If you want an output on the indicator in all cases, the indicator belongs after the case structures.

Overall, your code makes very little sense. How is the boolean switch supposed to be used and what is it supposed to do?

LabVIEW Champion . Oh, by the way, I work for peanutsKudos .

Member
Posts: 54

# Re: random number with upper limit

Random number is out of the bucle because i need to be generated only one. It is well, if i  put a random number in while loop the program generate very numbers and i need only one

The boolean buttom is for the user  presses this and the number appears

Member
Posts: 54

# Re: random number with upper limit

Ben.

No, not is multiepled by 45. Is less of 45

I need generate two number using the structure of VI atachhed, but these must be different.

The problem is that if is generate a number Greatter than 45, is generate a zero for default, then  Could to coincide with the other number.... In VI only you see one structure, the other for the other random number is equal, but i to compare the two number, for that no not equal to

Knight of NI
Posts: 22,798

# Re: random number with upper limit

[ Edited ]

Nothing you say makes much sense. Can you post in your native language and maybe google can translate it better.

You have more than one structure: a loop and two stacked cases. You have not fully define all possible outcomes:

• number is less or equal 45 and button is not pressed
• number is less or equal 45 and button is pressed
• number is larger than 45 and button is not pressed
• number is larger than 45 and button is pressed

What does "appear" mean? Should the number disappear if the switch is changed again?

In your first post you say you want two different numbers, but later you say you only want one number. Please explain.

LabVIEW Champion . Oh, by the way, I work for peanutsKudos .

Knight of NI
Posts: 13,225

# Re: random number with upper limit

Random number gives you a number between 0 <= x < 1.   Zero is included, one is not.  Multiply by 45 and round down to nearest integer.  Now you have a number from 0 to 44.

Member
Posts: 54

# Re: random number with upper limit

Escribiré en mi idioma "nativo"

Labview genera un número alaeatorio, cualquiera, luego es multiplicado por cien y por último redodeado, para que sea un número entero.

luego se pregunta si es mayor que 45, en el caso falso, entra en otra estructura case, en la cual, ante una pulsación del boton booleano se indica el número generado.

EL problema es que ésto funciona muy bien cuando el número que genera por defecto labview es menor que 45, porque cuando no es así, pues por defecto sale un cero. Mas adelante usaré una estructura similar a la aqui mostrada para otro número, y al oprimir el boton booleano, se generaran los dos numeros, antes haré una comparacion para que estos sean distintos, pero el problema será si por ejemplo los dos números aleatorios son mayores a 45, porque entonces tendré dos cero y yo requiero que sean distintos.

Member
Posts: 54

# Re: random number with upper limit

Lo que necesito es saber si puedo limitar para que siempre me salga un numero entre zero y 45

I want to know if I can limit the random number to always generate a number  between 0 and 45

Gracias

Thanks

Knight of NI
Posts: 13,225

# Re: random number with upper limit

angoav98 wrote:

I want to know if I can limit the random number to always generate a number  between 0 and 45

Gracias

Thanks

Yes.  If you do what Ben and I said about multiplying the output of the random number generator by 45 and rounding down.  Or if you want 0 to 45 including the number 45, then multiply by 46 and round down to the nearest integer.

By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
 My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page