# Tag Info

### i want get random number between 100-999, as follows

Since you're using the blockhash as your random number seed, this is actually a pseudo-random implementation. See this post for more information. To do this correctly, you'd want a decentralized ...
• 11.7k

### Can we use block hash as verifiable randomness for the off-chain lottery?

we want to use the block hash of some block in the future as a seed for the random generator. I think using a future block hash is generally considered "safe". (This article discusses using ...
• 37.9k
Accepted

• 11k

### i want get random number between 100-999, as follows

Between min and max: randomness % (max - min + 1) + min Between 1 and max: randomness % max + 1 Where randomness is uint obtained from Chainlink VRF or from any other source
• 171

### How is consensus in the state achieved if contracts have random output?

The contract provide deterministic outputs there is no rand function in the smart contract. you could try to write your own rand function using for example the block time stamp as a base. However, for ...
• 18.8k
Accepted

### i want get random number between 100-999, as follows

What you want is a random number within a range of 900 options. So do this: function random() internal returns (uint) { uint randomnumber = uint(keccak256(abi.encodePacked(now, msg.sender, nonce)...
• 8,068
Accepted

### "selfdestruct" deprecated in Solidity 0.8.18

You're perfectly allowed to keep using it, the depreciation has been put in place because the SELFDESTRUCT opcode most likely going to be deleted in an upcoming fork (https://eips.ethereum.org/EIPS/...
• 4,337
Accepted

### Any Pseudo Random Number Generator that can generate different numbers in the same block?

You can use an incrementing nonce each time a number is generated. This would have a large effect on the hash output. Random 0-100 Example: contract Random { uint nonce; function random() ...
Accepted

### Block archived event inside blockchain

You have to do it without relying on anything that triggers at that moment. You use the block.number to decide if bets are allowed. function isOpen() { return(block.number <= deadline); } ...
• 55.4k

### How to generate a unique random number in web3.js?

There is a util that can create "cryptographically strong pseudo-random HEX strings from a given byte size." You could then convert this to a number. web3.utils.randomHex(size) --> documentation Per ...
• 1,481
Accepted

### What is the purpose of using a true random number for an NFT?

A common problem in the traditional web2 art and trading card world is the transparency of randomness and scarcity. If you buy a trading card, like a PokÃ©mon card for example, you have no way of ...
• 11.7k

### How Chainlink VRF fulfillRandomWords() callback function works?

In the import VRFConsumerBaseV2.sol you will see the actual function being called by the VRFCoordinator is: function rawFulfillRandomWords(uint256 requestId, uint256[] memory randomWords) external { ...
• 607

### a question about oraclize api

It's a bit tough to explain completely. But there's an oraclize contract on the main net and testnets (Kovan, Rinkeby, Ropsten..) which you can import and use it's functions. Then after your ...
• 2,835
Accepted

### Can an Ethereum key generated on a laptop be brute-forced by someone else because of low entropy?

Generally a working laptop will have sufficient entropy, especially when it's been running for a while, as it has lots of places to get it from, such as you typing on your keyboard and moving the ...
• 16.9k
Accepted

### Are future block hashes viable as an RNG?

Yes and no. There's always a bit of risk involved with using block hashes as a source of entropy--if the value of the bet is far greater than a block reward, miners can potentially game the system a ...
• 1,128

### How is consensus in the state achieved if contracts have random output?

There is no true randomness in contracts. In this case, the contract is requesting that Oraclize fetch a random number from random.org. You are trusting both that random.org is honest, and that ...
• 37.1k
Accepted

### How to limit N bytes to value range using Oraclize Ledger-Proof Random Number -- unfair raffle

So your solution of discarding the numbers is known as rejection sampling and is indeed the way to solve your issue for your given inputs. As you've also noticed, there is a cost associated with this ...
• 567

### TypeError: Wrong argument count for function call: 2 arguments given but expected 1. Use abi.encodePacked

As the error says, you need to use abi.encodePacked: function random() private view returns (uint8) { return uint8(uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty)))%251); } ...
• 3,343
Accepted

### Can someone read this private variable?

private in the context of solidity smart contracts doesn't mean the value is a secret. It just means the variable is incapsulated and another contract will not be able to reference it directly. ...
• 171
Accepted

### How can you cheaply choose from a dynamic array randomly, with an oracle generated seed number, in Solidity?

Good Vibes is right. Modulo and you're done. The discussion gives me the impression that you don't fully understand how the remainder function solves it. There is no divide by zero, no need to ...
• 55.4k

### What are the costs of using Chainlink to generate a random number using VRF?

I've had a similar question. As far as I can tell, at the time of writing, the cost of a request to the Chainlink VRF (Verifiable Random Function) v2 on the Ethereum Mainnet is 0.25 LINK, which is ...
• 131
Accepted

### Can we use block hash as verifiable randomness for the off-chain lottery?

It would be better if we use Smart Contract Toolkits such as Verifiable Delay Function (VDF) from StarkWare Veedo Random Generator or ChainLink Verifiable Random Functions (VRF) instead of the simple ...
• 390

### ETH 2 random election attack vectors?

I am not sure I understand the question, but Eth 2 works this way : during an epoch n, each proposer signs some predetermined verifiable value which will produce a randao reveal (see here). The XOR of ...
• 1,120

### What happens if by randomness you deploy a contract to the same address then an existing EOA

You should check EIP-3607 Ethereum addresses are currently only 160 bits long. This means it is possible to create a collision between a contract account and an Externally Owned Account (EOA) using an ...
• 1,977
Accepted

### How to generate secure and pure Randomness number without Chainlink VRF?

It's much easier to create 'good' randomness off-chain. So you have lots of options to choose from off-chain. The difficult part is getting that randomness on-chain in a trustless manner. With your ...
• 29.7k
Accepted

### Is ChainLink's VRF susceptible to a 51% attack?

In Chainlink VRF, they are generated by one specific node, not by multiple nodes. There is no 51% attack because there is not a aggregating contract for Chainlink VRF. Maybe your next question is how ...
• 655

### How do I make a contract mint NFTs randomly with a metadata that's already on IPFS?

Yes, you are correct that Chainlink VRF is a good solution to generate a random number at mint time for your NFT, and it can help to prevent any potential exploitation of the contract. Here's example ...
Accepted

### Can PREVRANDAO be written as a random number on chain?

PREVRANDAO doesn't generate a new random number itself. For secure and unbiased random number generation on-chain, it's advisable to use external oracles, verifiable off-chain computations, or ...
• 281