LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

newbie question on a lottery vi

Solved!
Go to solution

I've been through the forum, and have found a few ways to do this, but I have an array problem: I set mine up to generate the initial five numbers and a door prize-winning "powerball," but my issue is how can I get the array of five to show each number in a different cell in the array, rather than in every cell at the same time. I think I need an array constant somewhere, but with a while loop in the for loop, I can't seem to come up with the desired operation.

Here's a copy of my vi and a pic of the "spaghetti"

 

Also, I'm running on my version 9 student edition.

 

Thanks for any help.

Download All
0 Kudos
Message 1 of 17
(5,315 Views)

Take Index Array & do whatever you want ..

 

http://zone.ni.com/reference/en-XX/help/371361J-01/glang/index_array/

 

I have some suggetions,

 

1. why you kept bigger Forloop with N value "1". It's not required (if you want to execute for 1time).

2. In side For loop also same.

3. suppose if you want to change N value more than "1" then  why you want Shift register for Inside for Loop ??? because your not doing anything with that value (for next itteration). Change Tunnel Mode and Select Last value.

 

Munna
0 Kudos
Message 2 of 17
(5,298 Views)

There some fundamental errors in your vi. 

 

As it has already need said, a For Loop with an 1 wired to N does not make any sens.

A Delay outside the For loop, and a delay in a For loop that only runs one time is not needed.

 

To your real problem, to get a array of the values that has been selected.

Wire the output from the while loop to antoher output out of the For loop that runs 5 times and select the tunnel to be Indexing. That will create an array of your values. That is the array you can display.

0 Kudos
Message 3 of 17
(5,281 Views)

lotto.png

 

  • generate random #s up to 40
  • search 1d for non repeating #s in the shift register
  • AND the results with the elapsed timer and build the array
  • array size = 5, stop vi.
0 Kudos
Message 4 of 17
(5,250 Views)

-

0 Kudos
Message 5 of 17
(5,238 Views)

As others have said, there are many things wrong with your code:

 

  • Lower FOR loop has no purpose
  • Outer FOR loop has no purpose
  • None of your delays serve any purpose
  • Your "reinit to default" occurs in parallel to the other two inner loops, so depending on the order of events, the result can be unexpected.
  • Don't use colors on the diagram, it lowers the contrast with other code elements (e.g. wires) and makes the code hard to read.
  • In the inner FOR loop you are creating an array with 5 identical elements. Why?
  • You are dealing with integers, so don't use orange datatypes

 

You are using way too much code for such a simple problem!

Here's a quick solution (5 of 59 and 1 of 35, as specified here). modify as needed.

See if you understand how it works.

 

 

 

 

Download All
Message 6 of 17
(5,236 Views)

And here's how you would animate the numbers at 0.5s intervals instead. Dataflow!

 

 

Download All
0 Kudos
Message 7 of 17
(5,218 Views)
Solution
Accepted by topic author hungryhobbit

@apok wrote:

 

  • generate random #s up to 40
  • search 1d for non repeating #s in the shift register
  • AND the results with the elapsed timer and build the array
  • array size = 5, stop vi.

There are several problems with your version:

 

  • You are creating random numbers 0..39 instead of 1..40
  • Since the elapsed time resets whenever it expires, it will take 3 seconds longer whenever a duplicate is found. For example it will take 6 seconds between numbers if a duplicate is found on the first attempt and 9 seconds if two duplicates are found, etc.
  • You are creating random numbers every 100ms, but discarding everything until the time has also elapsed.

here's a quick alternative of your code.

 

 

 

 

0 Kudos
Message 8 of 17
(5,204 Views)

This is exactly what I envisioned, but I don't have the experienc to implement. Thanks so much; it's really "elegant" code. Thanks to all you LabView wizards for the variety of solutions. That is to me the best thing about LabView.

0 Kudos
Message 9 of 17
(5,150 Views)

I think the riffle solution is cleaner. Did you try it?

 

The last solution is a bit inelegant and can cause problems in the more general case. For example if you would set N higher than the possible number of values, the VI would be trapped in the inner while loop forever because every possible value would be a duplicate after a while.

0 Kudos
Message 10 of 17
(5,132 Views)