キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

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

0 件の賞賛
メッセージ1/15
5,147件の閲覧回数

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

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 件の賞賛
メッセージ2/15
5,140件の閲覧回数

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?

0 件の賞賛
メッセージ3/15
5,139件の閲覧回数

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


0 件の賞賛
メッセージ4/15
5,133件の閲覧回数

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

0 件の賞賛
メッセージ5/15
5,130件の閲覧回数

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.


0 件の賞賛
メッセージ6/15
5,117件の閲覧回数

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.

0 件の賞賛
メッセージ7/15
5,115件の閲覧回数

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.

 

0 件の賞賛
メッセージ8/15
5,107件の閲覧回数

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

0 件の賞賛
メッセージ9/15
5,105件の閲覧回数

@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.

0 件の賞賛
メッセージ10/15
5,102件の閲覧回数