LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help making a random number generator within a specific range

Solved!
Go to solution

I am taking a college course that requires us to use Labview but doesn't explain it much. On a test today I was thrown when it asked for us to "create a random number generator that creates values between 20 and 40, use that to get 3 values then average them." It was more complicated than that with multiple steps after that, but I got stuck on the random number generator part. 

 

We are using Labview 2019 on campus but I'm using 2020 at home. I know there is a random number generator range VI, but not in 2019. So my main question is how to get it to stop after 3 number and average them. I attached what I have so far, but I don't know where to go from here. I know there are probably very easy ways to do this but we have to do the most tedious basic way. If we use advanced things or ways of doing it we get penalized. 

 

We have gone over basic things like arithmatic functions, boolean functions, shift registers, for and while loops, case structures, and thats about it. I think I'm just lacking the true understanding of the shift registers and loops. Any help is appreciated, Thanks. 

0 Kudos
Message 1 of 8
(4,098 Views)

The first thing that you will need to do is to generate those 3 numbers, it can be generated within a for loop. Since for loops are more suitable to work as arrays or specific iterations, (in your case 3) you can make it to run 3 times, inside the for loop putting the dice random number generator, on the output you'll need to have indexing tunnels for work as an array, and save the value for each iteration. After that there's a VI for get the mean value of an array, but if you want to program it for yourself, again using for loops you can achieve that, but now you'll need to get the sum of that values and then divide the number of values that you have been adding in this case the array size: you can save this image and paste it in your labview enviroment:

random mean.png

0 Kudos
Message 2 of 8
(4,080 Views)

Thank you, but that's still to complicated for where I am right now in the program. I don't know how or where you got the mean function. I took what you did and was able to get it to work. I attached what I have. I know there are far more elegant way to do it. But they only want us to use what we were taught. It's like going through 2/3rds of Calculus I and THEN they show you L'Hopitals Rule. They want you to understand the component level stuff first I think. I still can't figure out how to do this without and array. I think he wants us to do it with a shift register, but I can't figure out how.

 

Edit: And I just noticed you have the random number generator being multiplied by 20. That would give me a max value of 20, I need a number between 20 and 40, without using the random number range VI. Only thing I can think of is to "filter" out the number somehow. Which is why I made it go thru a logic test 20>x<40, if so then it passes thru. If not it would not pass thru, but I need it to somehow not count that iteration on the for loop. If it generates 3 number and none are in that range then I won't have a usable number. That's my biggest hangup. 

0 Kudos
Message 3 of 8
(4,061 Views)

I do not have LV20 installed on my computer, would you please share it as an image so I can take a look?

0 Kudos
Message 4 of 8
(4,055 Views)

Here's the first one, and the second one I got to work

Download All
0 Kudos
Message 5 of 8
(4,045 Views)
Solution
Accepted by topic author CumberdictBenderbatch

Gotcha, shift registers can also be used on For loops, if you want to use this in a single for loop do something similar like this:

Mean.png

 

And also since your range is from 20 to 40, you got 20 values in between so you should multiply the dice value since is 0-100% and then add another 20 since is where your range starts; You can still learn outside the school, it's what you are doing right now, so don't be afraid of using things that your courses does not include, specially in programming!

0 Kudos
Message 6 of 8
(4,032 Views)

Thank you so much! That's exactly what I was looking for! It's so simple now. The way you did the range on the random number generator makes so much sense now. I have to view it as a percentage, now a true number. Genius. And for the shift register, does it only output they data after the loop has ran? I understand how its storing the data by just adding to itself. So then when the loop is done, then it outputs to the divider circuit? I'm kinda trying to understand the order of operations in Labview. I'm familiar with Python how it runs the code one line at a time instead of compiling all at once. Love python, took Java the next semester then proceeded to drop it and change majors. Lol. 

 

Yeah idk if you've been in college recently but I'd say 75% of my learning has occurred outside of the class, now with COVID probably 90%. My university, like most, was extremely underprepared; so online classes are terrible. Take a guy who's been teaching in person for 20 years and hates computers and force him to teach on one doesn't go so well. I honestly like the Labview program, but what is it's purpose? Is it solely teaching, how do you convert it into real world applications? I'd like to use it to start building things and prototyping. Thanks! 

 

Here's my edited version

0 Kudos
Message 7 of 8
(4,015 Views)

You can do what you want as any programming language, I've made several applications from Data Acquisition to a Silent software installer for mass production of testers. The only disvantage I can tell comparing to other programming languages is that the runtime when creating .exe applications is way more heavier that python, c++, java. I've finished my university studies last year! luckly before COVID but I got your point, no one was prepared for this.

Good luck and always enjoy programming!

0 Kudos
Message 8 of 8
(4,006 Views)