ACS6 - Random Number Provider Standard

If your contract is about to generate a random number, you can consider using acs6.


To provider a random number according to certain input, you only need to implement one interface:


Method Name Request Type Response Type Description
GetRandomBytes google.protobuf.BytesValue google.protobuf.BytesValue Get the random number provided by this contract.


All you need is to override this method to return a random number according to the given input. You can decide the certain logic of generating random number yourself, just remember to return a BytesValue type, thus the caller can deserialize the output himself.


The easiest implementation:

public override BytesValue GetRandomBytes(BytesValue input)
    var serializedInput = new GetRandomBytesInput();
    var value = new Hash();
    var randomHashFromContext = Context.GetRandomHash(value);

    return new BytesValue
        Value = serializedInput.Kind == 1
            ? new BytesValue {Value = randomHashFromContext.Value}.ToByteString()
            : new Int64Value {Value = Context.ConvertHashToInt64(randomHashFromContext, 1, 10000)}.ToByteString()