# How does Proof-of-Stake works programmatically

I've researched on the internet, but am still confused about how Proof-of-stack works programmatically.

As mentioned here, in Proof-of-Stake system, A random Nextcoin is selected to be the next "miner". Which node is designated to randomly select a node as the next "miner"? Or in other words, how can a system agree on a random number in a way that can't be manipulated?

In most proof of stake systems, there isn't really some node that says "this node is the next staker". Rather what many do is, using data from the blockchain, calculate a set of public keys (the set can just be one public key) that can be the next staker. If a node that has the private key for one of those public keys is online, they can construct the next block.

The way that the set of public keys is determined varies by coin, but they all use data from the blockchain and a deterministic algorithm so that all nodes will come to the same set of public keys.

The randomness in these algorithms typically comes from hashing data which could not have been known beforehand (e.g. for block `n`, take the hash of block `n-1`). In this way, a random number is generated such that all nodes on the network will generate the same number.

• Is this correct: all the nodes shares the same algorithm to generate the public keys from the blockchain. Then after block `n-1` is generated, all the nodes shares another algorithm so that they will agrees on a public key to determine the `miner` for block `n`. – Steven Luo May 15 '18 at 8:24
• They don't share anything, they use the same algorithm, so given the same blockchain, they will calculate the same thing and thus agree on the public keys. But yes, your idea is correct. – Andrew Chow May 15 '18 at 14:37