LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create a VI that continuously generates random numbers between 0 and 1000 until it generates a number that matches a number selected by the user.

Guys I need help from here (im stuck) and also using just this 3 function on the front panel without using any else.

0 Kudos
Message 1 of 12
(8,921 Views)

Hi John,

 

have you done any basic tutorials?

 

check.png

What's the point of that OR function in your VI? Why did you wire a DBL indicator to a boolean OR input?

Why don't you use the +1 function? Why was the #iterations a DBL indicator?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 12
(8,912 Views)

You are dealing with integers. It is extremely dangerous to have a loop stop on a comparison with DBLs. Except for the random number generator, most of the diagram must be blue!

 

It is also a poor choice to have the "number to match" default to zero, because zero can never happen in your code and the loop will never stop! Make sure to configure the data entry and default value of all controls before saving.

0 Kudos
Message 3 of 12
(8,892 Views)

Here's one relatively safe possibility: (Make sure that the number to match is actually possible.)

 

altenbach_0-1587322538220.png

 

0 Kudos
Message 4 of 12
(8,885 Views)

If you need numbers in the range from 0 to n you have n+1 possible values 😉

From Help:

Produces a double-precision, floating-point number between 0 and 1. The number generated is greater than or equal to 0, but less than 1. The distribution is uniform.

 

So check how you coerce ...

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 5 of 12
(8,843 Views)

There is a Random Number (Range) VI in the numeric palette.  Use that to make your life a little simpler.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 12
(8,835 Views)

Although not mentioned, perhaps you want to pick each number only once?

Random From 1000 Numbers.png

 

0 is included (so technically, it's between -1 and 1000), but I hope you get the picture.

 

Here's a variation:

Random From 1000 Numbers (2).png

Message 7 of 12
(8,821 Views)

wiebe@CARYA wrote:

Although not mentioned, perhaps you want to pick each number only once?

Random From 1000 Numbers.png

 

0 is included (so technically, it's between -1 and 1000), but I hope you get the picture.

 

Here's a variation:

Random From 1000 Numbers (2).png


That loop 'only' create numbers from 0 to 999  😄

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 8 of 12
(8,808 Views)

@Henrik_Volkers wrote:

wiebe@CARYA wrote:

Although not mentioned, perhaps you want to pick each number only once?

Random From 1000 Numbers.png

 

0 is included (so technically, it's between -1 and 1000), but I hope you get the picture.

 

Here's a variation:

Random From 1000 Numbers (2).png


That loop 'only' create numbers from 0 to 999  😄

 


AFAIC, The 999 is correct, I mentioned the 0.

 

"Between 0 and 1000" (mentioned in the title) is from 1 to and including 999, not including 1000, right?

 

Anyway, I'm sure that can be fixed to meet the demands.

0 Kudos
Message 9 of 12
(8,798 Views)

So, how often do you have to generate a random number to match your selection?

guess how the histogram looks like...

random1000+histogram.png

Spoiler
No spoiler 😄  .... however I didn't expected that result !
Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


Message 10 of 12
(8,797 Views)