> For the complete documentation index, see [llms.txt](https://docs.swappi.io/swappi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.swappi.io/swappi/products/lottery/how-are-winners-determined.md).

# How Are Winners Determined?

Lottery uses works as follows:

1. After the on-going lottery round expires, two block numbers are selected: the latest one on the chain is obtained (Block A) and a future yet-to-be-produced block (Block B).
2. A third random number, $$s$$​ is selected as a salt.
3. Block A and the salt *s* are chained together and hashed with SHA-3 to get a digest *D*.
4. The digest D is put on-chain and the round for the lottery is closed to prohibit the purchase of new tickets.
5. After Block B is mined, both Block A and the salt are uploaded to a random number contract, which verifies that the digest matches the uploaded block number and salt in step 3.
6. The random number contract verifies that the digest matches the uploaded block number and salt and then takes the block hash and salt corresponding to the block number and does a SHA hash to calculate the final lottery result.&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.swappi.io/swappi/products/lottery/how-are-winners-determined.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
