elements
elements copied to clipboard
RPC example or tutorial opcodes enabled by liquid
"DETERMINISTICRANDOM" is something that of interest but I would like to see how it can be done by RPC.
Is there a way to test this function?
It's not a function nor RPC, it's an opcode ie. it's a specific byte (0xc0 = 192), which when included in bitcoin script has a specific function.
When this opcode is being executed by the script interpreter, it appears to work as follows:
- the stack must have at least 3 items, from the top of the stack these are: random seed, min value, max value
- if min > max, fail
- if min = max, push the min value back onto the stack
- initialize a CSHA256 hasher with the seed provided from the stack
- use this hasher with a deterministic algorithm to generate a random number between the given min and max
- pop the 3 stack items and push the deterministic random number onto the stack
For a given (seed,min,max) this will always produce the same random number (it is deterministic)