01-04-2018 11:15 AM
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
Solved! Go to Solution.
01-04-2018 11:28 AM - edited 01-04-2018 02:10 PM
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. 😄
01-04-2018 11:36 AM
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
01-04-2018 12:04 PM
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)
01-04-2018 12:10 PM
@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?
01-04-2018 12:29 PM - edited 01-04-2018 01:39 PM
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.
01-04-2018 01:08 PM
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.
01-04-2018 01:49 PM - edited 01-04-2018 01:51 PM
Here's a quick version I just made. seems similar, but using the riffle index for simplicity. I am sure that improvements are possible.
01-04-2018 01:56 PM
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.
01-04-2018 02:14 PM
@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 🙂