<p>That contaracts wiki page may be out-of-date.
However, the loto example uses <code>rand float</code> which in the <a href="https://ripple.com/wiki/Contracts#data_access" rel="nofollow">data access</a> section of the wiki page is described as:</p>

<blockquote>
  <ul>
  <li>this number is deterministically created based on the hash of the collection of transactions or something</li>
  </ul>
</blockquote>

<p>That implies to me that it's random only in the sense that the contract itself, or any Ripple user, cannot guess what the value will be at run time, but once running all validators will use the same value.</p>

<p>This is similar to how some Bitcoin gambling sites work, using numbers based off the Bitcoin blockchain hash.</p>

CC BY-SA 3.0
2014-04-17T04:46:39.840Z
Right, for the contract to work, it would have to be deterministic and only random in the sense that nobody could choose what its final output is.
David Schwartz
CC BY-SA 3.0
2014-06-12T14:49:58.863Z
This has yet to be implemented, but there are more possible details at https://ripple.com/forum/viewtopic.php?f=2&t=7084&p=51049#p50997
dchapes
CC BY-SA 3.0
2014-02-15T21:18:26.080Z
2014-02-15T21:18:26.080Z
dchapes
<p>There an interesting <a href="https://ripple.com/wiki/Contracts" rel="nofollow">page about contracts</a> on the Ripple Wiki.</p>

<p>My limited understanding of contracts is that like other transactions in Ripple, it is the consensus across many servers that ensures validity.  Am I right that when a contract is running in Ripple, the code runs on multiple servers and consensus ensures the contract's instructions are run correctly?</p>

<p>If so, I'm particularly curious about the "<a href="https://ripple.com/wiki/Contracts#Lotto" rel="nofollow">Lotto</a>" example on the wiki page.  It chooses one account randomly to be paid some amount of some currency.</p>

<p>If that code ran simultaneously on many Ripple servers, they'd each randomly choose a different winner.  How would they ever achieve consensus?</p>

<ripple><random><consensus>
How can a Ripple contract use random values and reach consensus?
Dave Cohen
# How can a Ripple contract use random values and reach consensus?

(Asked by: username_0 on 2014-02-14)

There an interesting [page about contracts](https://ripple.com/wiki/Contracts) on the Ripple Wiki.

My limited understanding of contracts is that like other transactions in Ripple, it is the consensus across many servers that ensures validity. Am I right that when a contract is running in Ripple, the code runs on multiple servers and consensus ensures the contract's instructions are run correctly?

If so, I'm particularly curious about the "[Lotto](https://ripple.com/wiki/Contracts#Lotto)" example on the wiki page. It chooses one account randomly to be paid some amount of some currency.

If that code ran simultaneously on many Ripple servers, they'd each randomly choose a different winner. How would they ever achieve consensus?

**Tags:** ripple, random, consensus


---

## 1 answers

### Answer by username_1 on 2014-02-15. Score: 1

That contaracts wiki page may be out-of-date.
However, the loto example uses `rand float` which in the [data access](https://ripple.com/wiki/Contracts#data_access) section of the wiki page is described as:

> * this number is deterministically created based on the hash of the collection of transactions or something

That implies to me that it's random only in the sense that the contract itself, or any Ripple user, cannot guess what the value will be at run time, but once running all validators will use the same value.

This is similar to how some Bitcoin gambling sites work, using numbers based off the Bitcoin blockchain hash.

> **Comments:**
> **username_2**: Right, for the contract to work, it would have to be deterministic and only random in the sense that nobody could choose what its final output is.  
> **username_1**: This has yet to be implemented, but there are more possible details at https://ripple.com/forum/viewtopic.php?f=2&t=7084&p=51049#p50997  

---

