# Technicals

{% hint style="success" %}
Promoting fairness and transparency with verifiable on-chain data!
{% endhint %}

Let's first break down how the monthly draw will happen from a technical perspective. Starting with the fact it will be facilitated with the following 2 items:

* Local Program (JavaScript)
* <mark style="color:purple;">Lucky Claw Smart Contract (Solidity)</mark>

Each month a lucky winner will be drawn using these two programs which will communicate with each other, here is the basic workflow / process:

<figure><img src="https://2971404703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FL4BmMBPcVr8jXJh1w52j%2Fuploads%2FtwRJDeB8TNgQybWxAM6p%2FScreenshot%202023-03-04%20at%2023.49.56.png?alt=media&#x26;token=bf5f73f1-2ad1-44a0-bc23-6df537b5f9f9" alt=""><figcaption></figcaption></figure>

In addition to helping automate / streamline the drawing process (by interacting with the smart contract, selecting / opening the winning animation / navigating to the winning NFT), the local program will be used to inject a random number into the smart contract. Before we jump into why this is important, we first need to understand an attribute of the Ethereum Virtual Machine.

{% hint style="info" %}
The Ethereum Virtual Machine (EVM) is deterministic system.
{% endhint %}

> In mathematics, computer science and physics, a deterministic system is a system in which no randomness is involved in the development of future states of the system. A deterministic model will thus always produce the same output from a given starting condition or initial state.

This means, creating a truly random number, on-chain, is actually impossible. Instead we have to settle for a pseudo-random number, created by combining a number of network variables such as block height and gas limit. This will be made truly random by inputting an off-chain variable as a parameter.\
\
As the Flare Network creates blocks every 1-2 seconds and the fact that the gas height changes frequently (depending on the demand of the network), these two variables are a great starting point for randomness.

In order to achieve true randomness we need to bring data off-chain, into the smart contract.&#x20;

```javascript
Math.Random();
```

The numbers (in a basic sense) are used to generate a very large number, subsequently the modulo operator (%) is used to output a minimum and maximum range (which will be 1 and the amount of NFTs minted).

```solidity
// Generate a random number and set the view state to hidden.
function generateRandomNumber(uint256 input) public onlyOwner {
    // Enter stealth mode
    hidden = true;
    // Set (current) mint amount
    mintAmount = ILuckyClaw(luckyClawAddress).totalSupply();
    // Generate a large random number
    uint256 random = uint256(keccak256(abi.encodePacked(block.difficulty, block.timestamp, block.gaslimit))) + input;
    // Rescale it to a number between 1 and the FCLC mintAmount
    randomNumber = random % mintAmount + 1;
}
```

The code snippet above comes from the publicly available smart contract deployed on the Flare Network, you can find it [**here**](https://flare-explorer.flare.network/address/0x5C672D7AF4B42a3c571d18436B96452Bf16b8150/contracts#address-tabs).


---

# Agent Instructions: 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://flare-community-lucky-claw.gitbook.io/get-started/fiarness/technicals.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.
