 kilee26
		
			kilee26
		
		
		
		
		
		
		
		
	
			03-27-2015 12:13 PM
I'm trying to build a code for a project. It's very simple.
I need to use either a random number generator which generates numbers 1 to 3 or I need to be able to enter a number in. Depending on whether the number is 1, 2, or 3, will determine what will happen.
For number 1, a green light will go on and a dialogue box with pre-entered text will pop up.
For number 2, a green light and red light will go on as well as another dialogue box with pre-entered text.
For number 3, a green light, red light, and two different dialogue boxes will pop up.
I really need help fast.. Thank you! 🙂
 pjr1121
		
			pjr1121
		
		
		
		
		
		
		
		
	
			03-27-2015 12:25 PM
This is a simple application of a case structure. What specific part are you having trouble with? What have you tried so far?
We are not here to do your work for you, especially since this sounds like homework. Post a VI of what you have attempted and ask specific questions about the sections of code you are having problems with.
03-27-2015 12:31 PM
 RavensFan
		
			RavensFan
		
		
		 
		
		
		
		
		
	
			03-27-2015 12:36 PM
That's not a LabVIEW question anymore, but a math question. Generating random numbers is something that should be taught in any basic programming class.
The random number generator gives a number from 0 to 1. Zero is part of the data set, 1 is not. So 0 to 0.999999999..
You want a range of 1, 2, 3 integers only.
Multiply by 3. Now you'll have a number from 0 to 2.999999 ....
Add 1, Now you'll have a number from 1 to 3.99999999....
Round down towards -infinity Now you'll have 1, 2, or 3.
 Thomas_robertso
		
			Thomas_robertso03-27-2015 12:37 PM
Take the random number function, multiply it by 2, round the result to the nearest whole number. That will give you 0-2. Then add 1 to get 1-3. Pass the resulting number to your case selector.
 RavensFan
		
			RavensFan
		
		
		 
		
		
		
		
		
	
			03-27-2015 01:03 PM
@Thomas_robertson wrote:
Take the random number function, multiply it by 2, round the result to the nearest whole number. That will give you 0-2. Then add 1 to get 1-3. Pass the resulting number to your case selector.
Wrong. You do not round to nearest. That only gives you half the probability for the numbers at the end of the range.
Multiply by 3 and round down.
03-27-2015 01:05 PM
 pjr1121
		
			pjr1121
		
		
		
		
		
		
		
		
	
			03-27-2015 01:15 PM
Wire the numeric control to the case structure control terminal (the green ? mark). Make a case for the numbers 1, 2, and 3. "if you are asking for these explanations you should really really really take the time to go through the LabVIEW CORE traning) It should only take a couple hours.
 Stuart.Parkinso
		
			Stuart.Parkinso03-27-2015 01:17 PM
Help -> Show context help.
Drop a case structure on the block diagram and hover mouse over it. The context help window displays a brief summary plus a link to detailed help text. Click the link,
You will find the LabView help system gives you answers much faster than a forum will, especially considering the general nature of your question. If you get stuck, come back with some code and a specific question. Its amazing what you will find out if you just look.
 Thomas_robertso
		
			Thomas_robertso03-27-2015 03:02 PM
Good point. I'll bet I coded some randomize routines wrong in the past... So round down is always the right thing to do. NI should revamp the random number function such that you can type in a range.