The PickWinnerExample contract, inheriting GeneralRandcastConsumerBase and calling functions in RandcastSDK, implements the functionality to pick a winner between two players.
The three important components of the contract are the constructor function, getWinner function and the callback function _fulfillRandomness.
Inside the constructor, we set the value of indexToName, this variable maps the indices to strings denoting the outcome of a game (Player 1 wins, player 2 wins, or tie).
The function getWinner is used to request a random number.
In the callback function _fulfillRandomness, we use the random number requested earlier to call the RandcastSDK.roll function. This gives us a random index between 0 and 2. This index corresponds to the win/loss result defined in indexToName.
In this example, the probability of player 1 and player 2 winning, losing, or tying are the same. Therefore, we can use the RandcastSDK.roll function to decide the outcome of the game randomly.