## Random Numbers – shuffling (and $300 Million)

$300 Million, is this enough amount of money for a good tiny program?

of course it is!

Well, current estimated jackpot is $300 million for this Saturday. oh my god! huh?

okay then, let make a tiny program to get me a luck.

– This is my idea.

1. I need to generate five random numbers form 1 to 55 without repeat.

2. another number from 1 to 42 independently.

int powerBall = generator.nextInt(42)+1;

3. open a text file of past winning numbers and, count those numbers.

4. add weight to generate random numbers based on the past winning numbers.

To implement, I think shuffling array would be the most easiest way.

int[] numbers = new int[55]; int length = numbers.length; for (int i=0; i < length ; i++) numbers[i] = i+1; for (int i=0; i < length; i++) { int position = generator.nextInt(length); int tmp = numbers[i]; numbers[i] = numbers[position]; numbers[position] = tmp; }

then we can pick 5 of them. with our lucky algorithm.

good luck!!

Advertisements

## Leave a Reply