# One article: understand the significance of random numbers for Web3

"Randomness" refers to an irregular or unpredictable state. For example, coin tossing, fingerprint patterns and the shape of snowflakes are unpredictable. Nature is full of randomness, but it is not so in the computer environment. One of the characteristics of computer is certainty, so it may not be possible to realize real randomness by only relying on a group of algorithms.

In addition, although a single random event cannot be predicted, the probability of different results of repeated events is predictable. For example, it is impossible to predict the result of one throw of the dice, but the probability of different results of 100 throw of the dice can be almost accurately calculated.

In the past few decades, with the increasingly frequent economic, social and cultural activities on the Internet, more and more people have called for simulating the unpredictability of the real world on the Internet and generating unpredictable results for the digital system. To achieve unpredictability, we must artificially create scarcity, create a more robust security mechanism, and implement a completely neutral decision-making process.

**This article will elaborate on the concept and types of random numbers, and discuss the challenges that random numbers bring to blockchain and Web3.**

**Is random number really random?**

Chainlink VRF has the following characteristics, which makes it an industry standard:

**Unpredictable——**The result cannot be known in advance.**Justice——**The probability of occurrence of each result must be the same.**Verifiable——**The results must be independently verifiable.**Tamper proof——**The process of creating random numbers cannot be manipulated by either party.**Cannot reproduce——**The process of creating random numbers cannot be repeated unless the original sequence is retained.

The computer is a predictable environment, which is composed of preset circuits, components and predefined codes and algorithms. Therefore, it is possible to predict the random number or random number sequence created by the computer under specific conditions. A computer can always generate a specific output based on an input. It's like you enter 2 + 2 in a calculator, and the result is always 4. Therefore, the computer cannot generate a real random number.

In order to solve this problem, the random number generator (RNG) usually uses seed as the initial value (input) of the calculation and generates the calculation result. This seed can be created based on any information that is difficult to reproduce, such as the data captured in the photo, the time point of the day, the user's mouse movement trajectory, or the movement trajectory of the lava lamp.

However, even if we say that the random number generation process is difficult to reproduce, it does not mean that it is impossible to reproduce technically. If multiple seeds that are difficult to reproduce are used as initial values to generate random numbers, the final result will be relatively more reliable, but there is still reason to believe that these seeds may be cracked eventually. Even if the same algorithm is used to generate different seeds, the results still cannot fully guarantee randomness. Then the question comes: what is a real random number?

**Pseudo random number generator vs true random number generator**

Generally, we can divide random number generators into two categories, namely, pseudo-random number generators (PRNG) and true random number generators (TRNG). PRNG uses mathematical algorithms to generate random values, while TRNG uses physical data such as environmental noise to generate random numbers.

The bottom layer of PRNG is a group of algorithms that create random number sequences by applying mathematical consensus to simulate real random numbers. Because the computer is a unique system, these numbers do look like random numbers to people, but in fact they may have some imperceptible laws, which can be found through a large number of statistical analysis.

TRNG uses unpredictable physical data, such as cosmic noise, isotope radioactive decay and static electricity in radio waves, to generate random numbers based on natural phenomena. TRNG "extracts" random numbers from physical phenomena, so this random number generation scheme is considered to be more robust and unpredictable than computers. But even so, the data used by TRNG may still be deterministic. If someone monitors the physical environment of TRNG scanning, they can also capture the same signal and crack the random number sequence.

The probability that the random number generated by TRNG is cracked is relatively small, but the cost of this scheme is relatively high, so it cannot be applied on a large scale. PRNG has another advantage over TRNG, that is, it can be reproduced. If the observer knows the starting point of the number sequence, he can reproduce the same random number sequence, so he can verify the generation process of random numbers, which is very helpful for Web3 applications using random numbers.

**What is the important value of random numbers to the blockchain?**

**The secure random number is the foundation of the blockchain encryption technology. The encryption hash function is the key element of creating the private key of the cryptocurrency wallet, which ensures that no one can crack the private key of the wallet.**It is estimated that,BitcoinThe possible private key combinations in the hash function SHA-256 used by the protocol are close to the number of atoms in the observable universe.

Distributed consensus is limited by throughput and delay at the bottom. Throughput refers to the number of messages that can be sent within a period of time; Delay refers to the time required for the network to send a message. There are thousands of distributed nodes on a public chain that reach a consensus. It is unrealistic for each node to send messages to all other nodes. In order to minimize the number of messages required to reach a consensus, bitcoin uses proof of work (POW) as a random number source to determine which node can add new blocks to the blockchain. Miners need to solve difficult calculation problems before they can successfully add new blocks to the blockchain. Therefore, the probability of multiple nodes solving the calculation problems at the same time is very low, which will reduce the number of messages needed to be sent by the network to reach a consensus.

**The proof of interest (POS) system usually uses random numbers to allocate the tasks of the verification nodes in a fair and unpredictable manner.**If a malicious attacker can manipulate the random number used in the filtering process, it can improve the probability of being selected, and thus threaten the security of the entire network.

Since the blockchain is open and transparent, all participants can see all inputs and outputs, so it is also possible to predict randomly generated series. For example, some schemes for generating random numbers on the chain (such as generating random numbers based on block hash) have obvious security vulnerabilities. If a miner or verification node wants to manipulate random numbers, it can choose not to publish blocks that are unfavorable to him, thus affecting the generation of random numbers. Doing so is basically tantamount to throwing the dice again and again until the final result is in your favor.

On the other hand, the off chain RNG solution lacks transparency. Users can only trust that the centralized data provider will not manipulate the results, and cannot judge the authenticity of random numbers. With the increasing value of RNG solution support, these two solutions are becoming more and more worrying.

**Random number of Web3**

**When it comes to blockchain games, NFT projects or digital art, people may not realize the importance of random numbers.**Web3 needs a secure random number source to achieve fair and unpredictable results, such as determining the placement of game props in the meta universe; Adding variables to the algorithm of Generative Art; Create the contents of the treasure box; Cast NFT; Reward the winners; Verify the event tickets; Or regularly elect members for the Dao Governance Committee.

These systems are of great practical value. If the results are manipulated due to the loopholes in the random number scheme, some participants will be unfairly treated due to information asymmetry. This will often lead to a vicious circle, and eventually lead to the complete collapse of the underlying economic mechanism and game mechanism of economic activities and social coordination.

It is not easy to obtain random numbers that are completely tamper proof, unpredictable, and verifiable by everyone. However, with the original intention of improving fairness and transparency, the Web3 industry has launched many applications and protocols, which surpasses similar applications of web2.**Random numbers can guarantee fairness and fairness, and can be verified safely. This unlocks a series of innovative applications, including blockchain games, NFT, decentralized governance, Web3 social media, charity fundraising, and social traffic cards.**

**Chainlink VRF**

Chainlink verifiable random function (VRF) establishes an industry standard for RNG solutions. Smart contracts and off chain systems can use off chain computing and encryption technology to obtain verifiable random number sources. VRF combines the block data (Note: when the request is initiated, the block data is unknown) with the private key submitted by the Oracle node in advance to generate a random number and an encryption certificate. The application only accepts random numbers with valid encryption certificates attached, and only the tamper proof VRF process can generate valid encryption certificates.

Chainlink VRF uses off chain computing and encryption technology to create a tamper proof random number source

Since its release, chainlink VRF has completed more than 6.5 million requests and output fair and just random numbers. Currently, chainlink VRF is avalancheEthereumandPolygonAnd more than 3400 smart contracts on each blockchain provide verifiable random numbers.

Chainlink VRF has the following characteristics, which makes it an industry standard:

**Unpredictable——**No one can predict the random number generated by chainlink VRF because the block data cannot be known when the random number is requested.**Fair and just——**Random numbers are generated based on uniform distribution, that is, all numbers have the same selection probability.**Verifiable——**Users can verify the encryption certificate of chainlink VRF on the chain to ensure the security of accessing chainlink VRF applications.**Tamper proof——**No one, including Oracle, external parties or development teams, can manipulate the random number generation process. If the VRF process is manipulated, the node cannot create an effective encryption certificate, and the smart contract will not accept random number input.**Open and transparent——**Since the code is open source, users can verify the random number generation process.

Chainlink VRF not only has the above characteristics, but also establishes a series of security mechanisms and continuously improves based on user feedback. For this reason, applications accessing chainlink VRF can use tamper proof RNG to generate fair and unpredictable random results, and unlock rich functions and experiences.

If you are a developer and want to quickly connect the smart contract to chainlink VRF, please check the developer documentation and join our technical discussion group on discord. If you want to arrange a conference call to discuss the integration details, please click here to contact us.