jeudi 31 mars 2016

What is a way I can make this raffle system code provably fair?

The following code is for a type of raffle, in which users deposit items to receive tickets. There amount of tickets they received is recorded in a weighted table. This is how the winner selection looks as the table is filled. I am using http://ift.tt/1VW9CcC for simplicity.

var rwc = require('random-weighted-choice');
var table = [
    { weight: 100, id: "user1"}
  , { weight: 120, id: "user2"} 
  , { weight: 400, id: "user3"} 
  , { weight: 2220, id: "user4"} 
];
var winner = rwc(table);

I want to make it provably fair by assigning the specific ticket numbers to users. Then using some kind of true random number gen with sha 2 to select a ticket number. This way the user can check that the ticket chosen was the ticket number the server generated. However I am new to Nodejs and web apps in general so I do not know how to code this type of function. Any hints or examples would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire