Datastucture for random











up vote
0
down vote

favorite












I want to random pick an item from a list. This is no problem, but the size is worrying me.



I have a sort of lottery game where a user can buy one or multiple tickets. Each ticket is a chance to win. I need to draw some players from the list.



So I thought I am going to build a list like:



//loop over all the players
for loop
get the number of tickets
loop over the number of tickets
insert the user x times into an array


So when the user has 10 tickets, he is going to saved 10x in the array. So I can randomly draw someone from that list. But the problem is, I have around 1600 users with each 200k tickets or more.



What is the best way to do this?










share|improve this question






















  • Number each ticket, pick a random number?
    – jonrsharpe
    Nov 10 at 18:21















up vote
0
down vote

favorite












I want to random pick an item from a list. This is no problem, but the size is worrying me.



I have a sort of lottery game where a user can buy one or multiple tickets. Each ticket is a chance to win. I need to draw some players from the list.



So I thought I am going to build a list like:



//loop over all the players
for loop
get the number of tickets
loop over the number of tickets
insert the user x times into an array


So when the user has 10 tickets, he is going to saved 10x in the array. So I can randomly draw someone from that list. But the problem is, I have around 1600 users with each 200k tickets or more.



What is the best way to do this?










share|improve this question






















  • Number each ticket, pick a random number?
    – jonrsharpe
    Nov 10 at 18:21













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want to random pick an item from a list. This is no problem, but the size is worrying me.



I have a sort of lottery game where a user can buy one or multiple tickets. Each ticket is a chance to win. I need to draw some players from the list.



So I thought I am going to build a list like:



//loop over all the players
for loop
get the number of tickets
loop over the number of tickets
insert the user x times into an array


So when the user has 10 tickets, he is going to saved 10x in the array. So I can randomly draw someone from that list. But the problem is, I have around 1600 users with each 200k tickets or more.



What is the best way to do this?










share|improve this question













I want to random pick an item from a list. This is no problem, but the size is worrying me.



I have a sort of lottery game where a user can buy one or multiple tickets. Each ticket is a chance to win. I need to draw some players from the list.



So I thought I am going to build a list like:



//loop over all the players
for loop
get the number of tickets
loop over the number of tickets
insert the user x times into an array


So when the user has 10 tickets, he is going to saved 10x in the array. So I can randomly draw someone from that list. But the problem is, I have around 1600 users with each 200k tickets or more.



What is the best way to do this?







node.js






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 18:17









da1lbi3

1,25321733




1,25321733












  • Number each ticket, pick a random number?
    – jonrsharpe
    Nov 10 at 18:21


















  • Number each ticket, pick a random number?
    – jonrsharpe
    Nov 10 at 18:21
















Number each ticket, pick a random number?
– jonrsharpe
Nov 10 at 18:21




Number each ticket, pick a random number?
– jonrsharpe
Nov 10 at 18:21












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Why not use a json object as



{ "players" : [ { "player": id , "ticketsNu" : num } .... ]
"totalNu" : numb }


When it comes to choosing the winning ticket, then you have to calculate each players chances as



players.forEach((player)=>{ player.chances = player.tiketsNu / players.totalNu })





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242016%2fdatastucture-for-random%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Why not use a json object as



    { "players" : [ { "player": id , "ticketsNu" : num } .... ]
    "totalNu" : numb }


    When it comes to choosing the winning ticket, then you have to calculate each players chances as



    players.forEach((player)=>{ player.chances = player.tiketsNu / players.totalNu })





    share|improve this answer

























      up vote
      0
      down vote













      Why not use a json object as



      { "players" : [ { "player": id , "ticketsNu" : num } .... ]
      "totalNu" : numb }


      When it comes to choosing the winning ticket, then you have to calculate each players chances as



      players.forEach((player)=>{ player.chances = player.tiketsNu / players.totalNu })





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Why not use a json object as



        { "players" : [ { "player": id , "ticketsNu" : num } .... ]
        "totalNu" : numb }


        When it comes to choosing the winning ticket, then you have to calculate each players chances as



        players.forEach((player)=>{ player.chances = player.tiketsNu / players.totalNu })





        share|improve this answer












        Why not use a json object as



        { "players" : [ { "player": id , "ticketsNu" : num } .... ]
        "totalNu" : numb }


        When it comes to choosing the winning ticket, then you have to calculate each players chances as



        players.forEach((player)=>{ player.chances = player.tiketsNu / players.totalNu })






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 18:57









        gkont

        1039




        1039






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242016%2fdatastucture-for-random%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues