Linked Questions

3 votes
2 answers
3k views

Best practices for generating a random uint256 [duplicate]

I've read through this thread and this thread and they offer a lot of interesting techniques, but what's the minimal code snippet for the currently accepted method of generating a random number in ...
Mittenchops's user avatar
4 votes
1 answer
2k views

String of random characters [duplicate]

I understood that solidity can only generate pseudo-random numbers. Although, is there any way of generating a, let's say 10 character, random string?
João Quintanilha's user avatar
3 votes
1 answer
966 views

Are future block hashes viable as an RNG? [duplicate]

Let's say I want to make a gambling contract. Anyone can call the createWager function to create a new bet to flip a coin. When they win, in order to collect the payment for the wager, they have to ...
Jay's user avatar
  • 33
0 votes
1 answer
1k views

How to create random number in solidity except sha3? [duplicate]

I am using sha3 to create 3 unique id in a same function. But results are same for all of them because it is using timestamp like this "uint256 random = uint256(sha3(block.timestamp)) +1;". So, I ...
Shubhabrata Mukherjee's user avatar
2 votes
1 answer
468 views

Random number inside contract [duplicate]

It is possible to generate truly (not pseudo) random number with specific range inside smart contacts (for example I need random number between 1 and 60 000 ) Thx!
yanik's user avatar
  • 473
0 votes
0 answers
160 views

Is this a good way to get a random number on solidity? [duplicate]

I need to generate a random number for betting games. Is this pattern safety solution? mapping(uint => address) playerMapping; address[] players; // here is contract will save block.number of ...
Kutubek Kylychbekov's user avatar
3 votes
0 answers
102 views

Which is the safest way to generate a random number? [duplicate]

I need a function that generates a random number from 0 to n for the lottery. I found 2 ways to do that: 1. https://gist.github.com/alexvandesande/259b4ffb581493ec0a1c But miners can influence the ...
Maxim Ananko's user avatar
1 vote
0 answers
100 views

Solidity effective random number [duplicate]

How can i generate random number in contract? Like this: uint8(uint256(keccak256(block.timestamp, block.difficulty))%251); but we cannot trust miner, this is not 100% random Or use Oraclize: ...
Vitali Malinovski's user avatar
1 vote
0 answers
69 views

Oracles and randomness, Creating or solving problems? [duplicate]

The idea behind oracles as a way to outsource information to be off the blockchain (Verifiable computing), Can solve a lot of problems, mostly related to randomness, As well as interacting with other ...
Illasera's user avatar
0 votes
2 answers
66 views

What are the best up-to-date secure approaches of generating pseudorandom number in Solidity? [duplicate]

I am thinking about creating a lottery with more than one winner and one round for users. Please don't consider usual 'commit-reveal' scheme. However, person can claim rewards on their own at the end ...
Victor's user avatar
  • 13
0 votes
1 answer
40 views

Proof that a variable is truly random [duplicate]

I have thinking of the wonder that an application could offer if it could prove that some of its data are truly random and so not controlled. Can the ethereum blockchain offer such a service and how ...
Saxtheowl's user avatar
  • 678
40 votes
3 answers
12k views

Can a contract safely rely on block.timestamp?

How safe is it to use block.timestamp as contract expiration time? If a miner provides an incorrect timestamp in a block header, how much can it be off before it is rejected by other nodes? Is there a ...
J-B's user avatar
  • 8,961
14 votes
5 answers
41k views

Where can I find some Solidity / Smart Contract source code examples? [closed]

Is there an easy to access list of Solidity / Smart Contracts / Dapps source code examples? Related information: Is there a list of DAPPS that are already useable? Where can I learn how to develop ...
37 votes
1 answer
7k views

When can BLOCKHASH be safely used for a random number? When would it be unsafe?

I've seen more complicated ways for a contract to generate a random number. But the Ethereum Yellow Paper itself suggests a "trivial solution" using the BLOCKHASH opcode (see below, bold is mine). ...
eth's user avatar
  • 86.1k
5 votes
4 answers
12k views

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

function random() internal returns (uint) { uint random = uint(keccak256(now, msg.sender, nonce)) % 1000; nonce++; return random; } In this way, you can generate random numbers, but there ...
Kido's user avatar
  • 53

15 30 50 per page