> For the complete documentation index, see [llms.txt](https://docs.elrondbet.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.elrondbet.net/transparency-and-security/fairness.md).

# Fairness

### Card Flip SC Code:

```
 let mut rand_source = RandomnessSource::<Self::Api>::new();

        // Calculate a random number between 1 - 200 (x2), 1 - 300 (x3) and 1 - 400 (x4)
        let random_result = rand_source.next_u16_in_range(1, game_mode * 100 + 1);
        // The actual card is the rest from division + 1 since selected_card starts from 1
        let result = (random_result % game_mode + 1) as u8;

        // Caller LOST...
        if selected_card != result {
            self.distribute_tokens(collection, &token, &amount, false);

            return ( ManagedBuffer::from(b"unlucky"), result ).into();
        }

        // Caller WON!
        let multiplier = BigUint::from(game_mode as u32);
        let amount_won = &amount * &multiplier;
```

### RPS SC Code:

```
let mut rand_source = RandomnessSource::<Self::Api>::new();

        // Calculate a random number between 1 - 300
        let random_result = rand_source.next_u16_in_range(1, 301);
        // The actual card is the rest from division + 1 since selected_card starts from 1
        let result = (random_result % 3 + 1) as u8;

        // Caller DRAW...
        if selected_card == result {
            self.distribute_tokens(collection, &token, &amount, true);

            return ( ManagedBuffer::from(b"draw"), result ).into();
        }

        // Caller LOST...
        if (1 == selected_card && 2 == result) // rock loses to paper
            || (2 == selected_card && 3 == result) // paper loses to scissors
            || (3 == selected_card && 1 == result) // scissors loses to rock
        {
            self.distribute_tokens(collection, &token, &amount, false);

            return ( ManagedBuffer::from(b"lose"), result ).into();
        }

        // Caller WON!
        let multiplier = BigUint::from(2u32);
        let amount_won = &amount * &multiplier;
```

### Battle Arena SC Code:

```
 let mut rand_source = RandomnessSource::<Self::Api>::new();
        // Calculate a random number between 1 - 200
        let random_result = rand_source.next_u8_in_range(1, 201);

        // Caller LOST...
        if 0 == random_result % 2 {
            self.distribute_tokens(&game.creator, collection, &token, &amount_won);

            return ManagedBuffer::from(b"unlucky");
        }

        // Caller WON!
        self.distribute_tokens(&caller, collection, &token, &amount_won);
```


---

# 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:

```
GET https://docs.elrondbet.net/transparency-and-security/fairness.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
