5 ms·
Ask HN: How to generate a truly random and verifiable number online
I need to generate a truly random number. Of course, I could go on Random.org but it needs to be verifiable by anyone online. I need a public board or pure randomness.
I'm thinking something along the line of: "The number will be extracted at precisely 00:00 of the 21st January, from XYZ. XYZ could be the last digit of a stock price or something like that. Another idea would be to use the national lotto.
However, my problem is that the number needs to be between 1 and X and I don't know what X is/will be in advance.
I need to be able to get a verifiable random number between 1 and X which can be verified by anyone.
Is something like this possible? How?
- onion2k 9y agoThis is a question that's been floating around with regard smart contracts for a while. It's surprisingly hard. Quite a good discussion around it, with some suggestions: https://ethereum.stackexchange.com/questions/191/how-can-i-securely-generate-a-random-number-in-my-smart-contract https://ethereum.stackexchange.com/questions/191/how-can-i-s...
- cosbgn 9y agoThanks, I'll read it
- ColinWright 9y agoColour me stupid, but I don't understand what you mean by "verifiable" in the context. Probably there's a page somewhere that makes it obvious, but a quick search around didn't turn up anything that's clearly the right thing. What, exactly, do you mean by a "verifiable random number"?
- cosbgn 9y agoHi Colin, with verifiable I mean that I don't need to make a screen-recording of me going on Random.org and get the number. I want something which can be checked and verified by anyone, some sort of "true" unique random number, the national lottery could be one because anyone could open a newspaper/browser and check it, it would be really hard for me to fake it.
- ColinWright 9y agoSo what you need is a process which anyone in the future after time T_0 can execute. Everyone who does so will get the same result, and the result will be agreed by everyone to be "random". So, for example, after January 23rd anyone can get the exact number of shares traded in Apple on the NYSE on January 21st, take the natural log, discard the first six digits after the decimal point, and keep the next six digits as a random number from 0 to 10^6-1 inclusive. That's not necessarily evenly distributed so it doesn't necessarily meet all your criteria, but other than that, is it the sort of thing you mean?
- cosbgn 9y agoYes that's exactly what I mean. However I can't solve 2 problems on this kind of approach, first it's not within a range (e.g. 1 and 144) and secondly I'm not sure every number has the same probably to come out.
- ColinWright 9y agoThe second is what I say about being evenly distributed. The first is easy to solve. Get a result that's sufficiently fine-grained and in the range [0,1). Then scale up by X and round up. You can add randomness by pushing your number through a cryptographic hash function and treating the result as a binary number in the range [0,1).
- twobyfour 9y agoExcuse my ignorance, but what is the meaning of the differing brackets in the notation you're using: "[0,1)"?
- ColinWright 9y agoStandard mathematical notation to indicate whether the endpoint is or is not included. { x : a < x && x < b } <=> (a,b) { x : a <=x && x < b } <=> [a,b) { x : a < x && x <=b } <=> (a,b] { x : a <=x && x <=b } <=> [a,b] In the example above the questioner is asking about getting a number in the range 1 to X inclusive. That would be [1,X]. Random number generators can return numbers in the range 0 to 1, including 0, not including 1. You can write that as [0,1). If you want an integer n in [1,X] and you get reals r [0,1), you can create a function: f : [0,1) -> [1,X], f(r) = 1+floor(X*r) Always check the endpoints, and the expected frequencies.
- zuzun 9y agoNIST Randomness Beacon generates 512 random bits every minute and gives you full access to all historic values. https://beacon.nist.gov/home https://beacon.nist.gov/home