Example - Pick a Property
The PickPropertyExample
contract illustrates the utilization of GeneralRandcastConsumerBase
and RandcastSDK
to pick one of several predefined properties.
The contract structure is similar to the previous example. The main components include the constructor
, the function getProperty
which is used to request random numbers, and the callback function _fulfillRandomness
which is triggered after generating the random number.
In the constructor
, define each index to represent the properties of 'fire,' 'wind,' and 'water.'
The function getProperty
requests the random number to be used in the callback function.
In the callback function _fulfillRandomness
we call RandcastSDK.roll
to pick the index of the three properties. We can then get the property value by index from the propertyValue
mapping.
The reason to choose this RandcastSDK
function in this example is that we need to select one of the three properties with equal probability randomly, and RandcastSDK.roll
is designed for randomly picking a number within a specified range.
Last updated