Results 1 to 4 of 4

Thread: UK lotto numbers

  1. #1

    Thread Starter
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    669

    Post 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. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,525

    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

  3. #3

    Thread Starter
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    669

    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. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,525

    Re: UK lotto numbers

    Quote Originally Posted by BenJones View Post
    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
  •  



Click Here to Expand Forum to Full Width