# VRF

Generate random numbers in blockchain is not a native functionality. You can find a lot of examples but the best and most secure way to get one is using chainlink VRF.

## Lil' Villains use cases

We need to use this integration to generate a random number that is used as a seed for a distribution algorithm to assign random tokenIds between 1 to 7777 when a new token is minted.

You can see the code in the repository:

- [Request random number](../contracts/LilVillainsMinter.sol#lines-67)
- [Distribution algorithm](../contracts/LilVillainsMinter.sol#lines-196)

## How to test it

When you implement VRF contract in your solution maybe you want to do an integration test to be safe. To do that you have 2 options:

- Test it using VRF helpers: In this case, you have to do a fork of rinkeby testnet and configure your hardhat solution to use it as explained in this paper.
- Create a mock contract for the chainlink coordinator and deploy it in your tests to get a hardcoded number that simulates it.

### Mocked VRF Coordinator implementation

You can find the mocked contract [here](../contracts/__mocks__/MockVRFCoordinator.sol)

## Useful links

- [VRF helper](https://mirror.xyz/clemlaflemme.eth/v3O2NPRW75U5s5NG5CgsFlvNNw-TEFXB3LNjwaGqTI0)
- [Mocking coordinator](https://stackoverflow.com/questions/69089799/how-to-locally-unit-test-chainlinks-verifiable-random-function)
