# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Beginner question re: random number function & timing

Hello,

I am a student learning Labview. I am programming a Flashcard project for school. I have most of my code in place but am stuck on how to have 1 single random number be generated, and then wait for the user to enter a number in a numeric control before continuing on. I am supposed to use a sequence structure in the project. I need the user to see a set of 2 numbers to be either added, or multiplied. The user needs to then enter in their guess at the answer. The correct answer needs to be displayed, and then the loop starts over.

I am stuck on how to implement the random number function to only generate a single pair of numbers, and then have ther VI wait for the user input before continuing on. The answer should not be displayed until after the user has entered their guess.

I have included my VI so you can see where I'm at.

I appreciate any help or advice.

Thanks very much,

George

Message 1 of 14
(1,165 Views)

## Re: Beginner question re: random number function & timing

No need for a sequence structure.  But you should look into a State Machine and the Event Structure.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 2 of 14
(1,156 Views)
Highlighted

## Re: Beginner question re: random number function & timing

Hi crossrulz,

Thanks for the reply. My Professor requires a sequence structure as part of the assignment.

Thanks!

George

Message 3 of 14
(1,153 Views)

## Re: Beginner question re: random number function & timing

Hi George Spatta,

I am stuck on how to implement the random number function to only generate a single pair of numbers, and then have ther VI wait for the user input before continuing on. The answer should not be displayed until after the user has entered their guess.

Let me summarize your problem: you need a program that does step a, followed by step b, which enables step c.

To using "common wording": use a state machine!

On your current VI: what's the purpose of the sequence frame?

Why do you set the "answer" to be visible all the time?

Edit: I was a little bit slow - but now two (more experienced?) people advise to use the same pattern…

My Professor requires a sequence structure as part of the assignment.

Ask your professor about the purpose of that sequence. All it does is to enforce bad programming behaviour…

Best regards,
GerdW
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome

Message 4 of 14
(1,151 Views)

## Re: Beginner question re: random number function & timing

Hi GerdW,

Here is what I need to do. I'm sure there are better ways to do this practically, but these are the requirements I need to meet.

Thanks again!

George

Message 5 of 14
(1,136 Views)

## Re: Beginner question re: random number function & timing

I set the answer to be visible all the time so that while I was working out the rest of the code, I could see that the math functions were working properly.

Thanks,

George

Message 6 of 14
(1,133 Views)

## Re: Beginner question re: random number function & timing

Now that I think about it a little bit longer, the state machine really is not needed.  You can do this easily with just a While loop and an Event Structure.  Shift Registers will be needed.  Still see no point in the Sequence Structure.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 7 of 14
(1,132 Views)

## Re: Beginner question re: random number function & timing

Hi,

reading your requirements I see no point telling you you have to do things in a special order. There is no indication you have to provide the correct answer AFTER the user has given his "guess" (why do we need to "guess" for simple math?)

This is a very poorly written requirement sheet!

Best regards,
GerdW
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome

Message 8 of 14
(1,058 Views)

## Re: Beginner question re: random number function & timing

Hi GerdW,

I completely agree with you. It does however make sense to me that you wouldn't want to see the correct answer until you've provided your guess. I also found out that you can't really wire the "Stop" button to the While Loop when using the Sequence Structure. I have put it in the last frame which will only allow the user to stop the VI within the 2 second window I have put in. I know that the example may not be a great one, but it was what I was tasked to do, and am doing the best I can.

Here is what I've come up with for a finished VI.

Again I appreciate all of the time & help / advice.

Thanks,

George

Message 9 of 14
(1,029 Views)

## Re: Beginner question re: random number function & timing

Why not put a Event Structure in the second frame of the sequence structure? I agree with Crossrulz and GerdW on this is not even practical and introduces bad LabVIEW programming habits, but wouldn't that work?

Message 10 of 14
(1,010 Views)