LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Random number generation, odd and even determination etc.

Hello everyone! My name is Evripidis, I'm from Greece and I'm studying electrical engineering. Smiley Happy I have a project to work on LabView which has been a pain in the butt for a few days and I'm desperate for some help because it's starting to get on my nerves. I've done my google searches and stuff but either a) they weren't much of a big help or b) it was me who didn't understand much. So, the project goes like this:

Create a .vi that will generate random integer number, ranging from 0-100. Those numbers should be seperated (and shown) in 2 different tables (1 for odd numbers and 1 for even numbers). The number values should also be shown in charts, as well as their average value. 

First, I'm interested to understand how it's going to work and how I'm supposed to make this forsaken odd-and-even-seperation work as well. (Tried quotient and remainder, no luck so far making it work properly). Just getting my project ready without trying at all is the least of my concerns.

 

2nd. Don't hesitate to ask me anything if you have a problem understanding me. English is not my main language and it's getting kinda rusty Smiley Happy 

and 3rd. thank you for your time reading this post whether you reply or not.
Bear in mind that my LabVIEW version is the  32bit 9.0 version

Thank you!

0 Kudos
Message 1 of 18
(7,215 Views)

Hello Evripidis, welcome to NI Forums! 😄

 

I tried to do something to help you checking if a number is odd or even.

Please take a look at the Snippet below.

Odd or Even.png

 

This will simply generate a random number (0-1) and multiply this by 100 (so we have a 0-100 number). After, we round it to nearest and convert to U16  (I think that it might be a better way of doing this, but I don't have any ideas now). Then, the code divides the random number (0-100) by 2, which makes possible to check if a number is odd or even, by using the remainder. If remainder = 0, we got an Even number, otherwise it is Odd (remainder = 1).
If you understand this, please try to do something about your tables and graphs, and let's see how far you can go and where you will possibly stuck.

Hope this helps. Any doubts, don't hesitate to ask.

 

Regards

Mondoni
Message 2 of 18
(7,199 Views)

Hello, and  thank you for your quick reply!

It seems that the very few steps I made were correct ( multiplying the dice's value x100 and then rounding it) after that I got a little lost though. I'll get to work right away and come back later with the results, greetings!

Edit: Unfortunately I can't directly use the snippet because my LabVIEW version is the 9.0 one as I mentioned. I'll do it step by step!

0 Kudos
Message 3 of 18
(7,194 Views)

Yeah, my bad. I forgot this important detail.

Here you go the VI (2009).

 

Mondoni
0 Kudos
Message 4 of 18
(7,184 Views)

Thanks again, I'll tamper with it right now Smiley Happy

0 Kudos
Message 5 of 18
(7,178 Views)

@joaopam wrote:

 

Please take a look at the Snippet below.

Odd or Even.png

 


slightly elegant way....integers already rounds to the nearest, no need for round to nearest Smiley Wink

if you want even, then make the comparison 'equal to 0'

Example_VI_BD.png

 

Message 6 of 18
(7,152 Views)

Apok

I wasn't sure if integers already rounds to nearest 🙂 good to know that.

As I said previously, I know that are other ways of doing this. And your example is good. The select function was only used to feed the string indicator.
It looks like we have a minor Rube Goldberg Code here 😄

 

Regards

Mondoni
0 Kudos
Message 7 of 18
(7,138 Views)

You do not want round to nearest.  When you multiply by 100, you'll get a number between 0 and 99.99999.....   Round to nearest will give you an integer between 0 and 100. but the values of 0 and 100 will only occur half as often as the values in between.

 

You should round down.  Now you will have a number between 0 and 99 that all have equal chances of occurring.  If you want 1 to 100, then add 1.  If you want 0 to 100, then multiply by 101.

Message 8 of 18
(7,128 Views)

RavensFan escreveu:

You do not want round to nearest.  When you multiply by 100, you'll get a number between 0 and 99.99999.....   Round to nearest will give you an integer between 0 and 100. but the values of 0 and 100 will only occur half as often as the values in between.

 

You should round down.  Now you will have a number between 0 and 99 that all have equal chances of occurring.  If you want 1 to 100, then add 1.  If you want 0 to 100, then multiply by 101.


I feel really glad when you point this details. I didn't realize that.

Thank you for being such supportive, it's good to know that I'm learning even when I'm trying to help. 😄

Regards

 

Mondoni
Message 9 of 18
(7,126 Views)

I'm glad to be able to help point out something I learned years ago when I first learned Basic programming about how to do rounding.  It is something that is very easy to misuse if  you haven't come across it before.

 

One other point about using the round function on integers.  The even values would have a slightly higher chance of occurring then odd valuesc because LabVIEW does banker's rounding where values that are exactly equal to 0.5 get rounded to the nearest even integer.  So 6.5 would round down to 6.  5.5 would round up to 6.  So using regular rounding introduces slightly more biased results there.

Message 10 of 18
(7,119 Views)