-
Feb 25th, 2024, 02:51 PM
#1
Thread Starter
Fanatic Member
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) + " ");
}
}
}
-
Feb 26th, 2024, 03:22 AM
#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
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Feb 26th, 2024, 03:41 PM
#3
Thread Starter
Fanatic Member
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.
-
Feb 26th, 2024, 05:51 PM
#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…..
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|