> For the complete documentation index, see [llms.txt](https://realisticnode.gitbook.io/rnsetups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://realisticnode.gitbook.io/rnsetups/rncasino/guides/fair-play.md).

# Fair play

How every result is fixed before the bets close, and how anyone can check it.

Every result of rnCasino is **provably fair**: the number is fixed **before** the bets close, and after the spin anybody can check that it was not changed.

## How it works

1. When a round opens, the table picks a secret **seed** (64 random hex digits) and shows its **code**: the SHA-256 of the seed. The code is on the hologram and in `/casino fair`.
2. The seed decides the number. Nobody can change the seed without changing the code, and the code is already public.
3. After the spin, the table shows the seed. Now anybody can check it.

<figure><img src="https://i.imgur.com/zf9qeKq.png" alt="/casino fair: the code of this round, and the seed and code of the last one"><figcaption><p>/casino fair: the code of this round, and the seed and code of the last one</p></figcaption></figure>

The seed and the code can be copied by clicking them in the chat. The **Fair play** button of the More menu shows the last result and opens the same message.

<figure><img src="https://i.imgur.com/NGgtw45.png" alt="The Fair play button in the More menu"><figcaption><p>The Fair play button in the More menu</p></figcaption></figure>

## How to check a round

You need the **seed**, the **round** number and the **code**, all shown by `/casino fair` after the round.

1. **The code matches the seed**: the SHA-256 of the seed must be the code that was shown before the bets closed.
2. **The seed gives the number**:
   * `h` = SHA-256 of `seed:round` (the seed, a colon, the round number).
   * Take the first 8 hex digits of `h` as a number.
   * If that number is `4294967289` or more (`4294967290` or more on American tables), take `h` = SHA-256 of `h` and try again. This keeps every number equally likely; it is very rare.
   * The result is that number modulo **37** (European) or **38** (American, where 37 means 00).

Any SHA-256 calculator works (for example an online "SHA-256 hash generator": type the text, not a file).

### Example

|                                |                                                                    |
| ------------------------------ | ------------------------------------------------------------------ |
| Seed                           | `832cb5742e16f321a3b346575b47f2d0523c0e759628e2db708df99a2bc0059d` |
| Round                          | `42`                                                               |
| Code = SHA-256(seed)           | `ff8d2108536666406315de81046cc7bfe0766a330b57193e9a30af8651c83ea0` |
| SHA-256(`832cb574...0059d:42`) | `a023dabaa51b29e9...`                                              |
| `a023daba` as a number         | 2686704314                                                         |
| 2686704314 modulo 37           | **4**                                                              |

### With a script

```python
import hashlib

seed = "832cb5742e16f321a3b346575b47f2d0523c0e759628e2db708df99a2bc0059d"
round_number = 42
pockets = 37  # 38 on American tables

sha = lambda text: hashlib.sha256(text.encode()).hexdigest()
print("code:", sha(seed))

limit = 2**32 - 2**32 % pockets
h = sha(f"{seed}:{round_number}")
while int(h[:8], 16) >= limit:
    h = sha(h)
n = int(h[:8], 16) % pockets
print("number:", "00" if n == 37 else n)
```

## What it proves

* The result was fixed before the bets closed: neither the server nor an admin changed it after seeing the bets.
* Every number has the same chance: past results never change the next one. The History menu says so too, because "hot" and "cold" numbers are only a fun fact.
* A server started in a special test mode that forces results can't hide it: `/casino fair` then says in red that the results are forced.
