LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Lottery Generator

Solved!
Go to solution

I know there have been several posts regarding this so forgive any repetition. Every time the lottery comes around in the news, I always day dream of winning big yet rarely play (once in my life). I find it interesting to create pseudo-random vis so here goes my lottery one. It will continue to generate lotto numbers until it finds a repeat in the stack. Feel free to post comments or your interesting take on this!

 

Five

0 Kudos
Message 1 of 24
(5,813 Views)

Except right near the dice, your code should all be blue. Why are you carrying it all as DBL?

 

All you basically need is riffle array and taking the first N elements of the the riffled index output. 

 

That said, the lottery is basically a tax on the mathematically challenged that many are willing to pay for some obscure reason. 😄

Message 2 of 24
(5,801 Views)

LotteryGenerator

 

 

Two comments;

 

1) It looks like the array of Booleans used in the "Check if repeat winn...." loop can be replaced by a single true Boolean to init the SR and then to an "And" inside th For loop.

 

2) "Riches gained over night dwindle while riches gained by diligence increase." So I suggest you forget about the lottery but keep working at your LV skills.

 

Ben

 

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 3 of 24
(5,796 Views)

Altenbach, you are definitely right about type size so I changed to I16. No reason to use double other than the fact it automatically made the entire vi double after the RNG got put down. I will have to do more research on the functionality of Riffle.

 

Ben, you are right. Much faster to AND element by element than perform array manipulation.

 

While this is all in good fun, I am probably making more money practicing to win the lotto than actually spending $2 to play! (Changed Stop button)

0 Kudos
Message 4 of 24
(5,786 Views)

@Ben wrote:

 

2) "Riches gained over night dwindle while riches gained by diligence increase." So I suggest you forget about the lottery but keep working at your LV skills.

How to give multiple kudoes? 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 5 of 24
(5,778 Views)

FiveV wrote:

Ben, you are right. Much faster to AND element by element than perform array manipulation.


If you would sort the numbers, you can just do an equal on the arrays, eliminating the inner loop. You could even use U8 and pad/cast the entire combo to a single U64 and then just compare two integers.

 

Also, your 2D init array should probably be empty.

Message 6 of 24
(5,764 Views)

Wow, this is substantially faster converting to U64. I think that I got the padding correct. I constantly get confused on with LSB MSB. Regardless, excellent suggestion for optimization.

0 Kudos
Message 7 of 24
(5,745 Views)

Here's a quick version I just made. seems similar, but using the riffle index for simplicity. I am sure that improvements are possible.

 

PB1.png

 

0 Kudos
Message 8 of 24
(5,732 Views)

A couple more notes:

1. Instead of Not Equal and a -1 constant, use the Greater Than Or Equal To 0 function.  No need for a constant then.  Likewise, use Less Than 0 instead of the Equals and a -1 constant.

2. Your array should be initialized to be empty.  That would avoid one more comparison every iteration.

3.  Instead of getting the array size, just use the i terminal and add 1 (Increment function).

4. If you actually need 1 through 69, you need to multiply by 70, round down, and add 1.  Likewise, you need to multiply by 27 for the powerball in order to get 1 through 26.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 24
(5,720 Views)

@crossrulz wrote:

4. If you actually need 1 through 69, you need to multiply by 70, round down, and add 1.  Likewise, you need to multiply by 27 for the powerball in order to get 1 through 26.


While I agree on the other points. I think I still need to multiple by 69 to get uniform distribution. See more unoptimized code below 🙂

0 Kudos
Message 10 of 24
(5,708 Views)