Skip to content

Commit

Permalink
Update rand.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
juntao committed Apr 3, 2019
1 parent 0d67edf commit 0412fb3
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions docs/rand.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ The function prototype is `function rand() returns (uint)`. When calling `rand()
- The `Counter` will automaticlly increase after the `opRand` is called.


The developers should be aware of the usage of random number. See `getPureRandnum()` in following example. The return value of `getPureRandnum()` may be the same, because of the following limitation:
The developers should be aware of the usage of random number.

1. `Randomness Seed` depends on current block. It will be the same until receiving the next block.

2. `Nonce` depends on the transaction order. When you test in local environment and don;t produce a new transaction, you might get the same nonce.
2. `Nonce` depends on the transaction order. When you test in local environment and don't produce a new transaction, you might get the same nonce.

3. `CodeHash` will not change after you deployed the contract.

4. `Counter` depends on the the called time of rand(). If you call `rand()` twice in same code block, you will receive different results. On the other hands, if you call `getPureRandnum()`, the `rand()` is called on different code block, you may receive the same result.
4. `Counter` depends on the the called time of rand(). If you call `rand()` twice in same code block, you will receive different results.

Example 1
---------
Expand All @@ -56,8 +56,7 @@ Example 1
randnum = rand();
return randnum;
}
function getPureRandnum() public pure returns (uint) {
return rand();
}
}
> You should NOT call `rand()` in a `view` or `pure` function. If the random number does not need to be recorded on the blockchain (i.e., outside of a transaction in a `view` function executed on a single node), it does not need to be generated by the blockchain. The calling application should simply generate a random number locally -- it is much cheaper in terms of resource consumption.

0 comments on commit 0412fb3

Please sign in to comment.