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?
node.js
add a comment |
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?
node.js
Number each ticket, pick a random number?
– jonrsharpe
Nov 10 at 18:21
add a comment |
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?
node.js
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
node.js
asked Nov 10 at 18:17
da1lbi3
1,25321733
1,25321733
Number each ticket, pick a random number?
– jonrsharpe
Nov 10 at 18:21
add a comment |
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
add a comment |
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 })
add a comment |
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 })
add a comment |
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 })
add a comment |
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 })
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 })
answered Nov 10 at 18:57
gkont
1039
1039
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Number each ticket, pick a random number?
– jonrsharpe
Nov 10 at 18:21