# Thread: UK lotto numbers

1. ## UK lotto numbers

Hi this shows are to shuffle the contents of an array list so I made a little program to show it's usage hope you like it.

Code:
```import java.util.ArrayList;
import java.util.Collections;

public class Main {
public static void main(String[] args) {
//UK lotto
ArrayList<Integer>nums = new ArrayList<Integer>();
//Add the numbers 1 to 59
for(int x = 1; x<=59; x++){
nums.add(x);
}
//Shuffle the nums collection.
Collections.shuffle(nums);

//Print the first six numbers.
for (int x = 1; x <= 6;x++){
System.out.print(nums.get(x) + " ");
}
}
}```

2. ## Re: UK lotto numbers

*sigh*

and again people executing a full shuffle just to get the first x "random" numbers,
instead of actually sitting down, and studying how the Durstenfeld-Algorithm works

3. ## Re: UK lotto numbers

Never knew about the Durstenfeld-Algorithm thanks for the info should come in handy if I ever need to do something like this agian.

4. ## Re: UK lotto numbers

Originally Posted by BenJones
Never knew about the Durstenfeld-Algorithm thanks for the info should come in handy if I ever need to do something like this agian.
Do that.
in your case you execute (at least) 65 commands (59 for the shuffle plus the draw for the first 6, though it’s probably around 120 plus 6) plus overhead

Durstenfeld correctly used results in……. 12 executions plus overhead
those are of course only very rough estimates

do this a few million times…..

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Click Here to Expand Forum to Full Width