cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Lottery Generator

Solved!
Go to solution
Highlighted

Lottery Generator

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
(1,180 Views)

Re: Lottery Generator

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. Smiley Very Happy


LabVIEW Champion Do more with less code and in less time
Message 2 of 24
(1,168 Views)

Re: Lottery Generator

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

 

 

Message 3 of 24
(1,163 Views)

Re: Lottery Generator

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
(1,153 Views)

Re: Lottery Generator


@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
LabVIEW 2017
LabVIEW Programming
Message 5 of 24
(1,145 Views)

Re: Lottery Generator


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.


LabVIEW Champion Do more with less code and in less time
Message 6 of 24
(1,131 Views)

Re: Lottery Generator

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
(1,112 Views)

Re: Lottery Generator

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

 


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 8 of 24
(1,099 Views)

Re: Lottery Generator

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.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 9 of 24
(1,088 Views)

Re: Lottery Generator


@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 Smiley Happy

0 Kudos
Message 10 of 24
(1,076 Views)