Skip to main content

Random Number Generation

Inco Lightning provides on-chain encrypted random number generation through the e_rand function. This enables use cases like lotteries, games, fair distribution, and any application requiring unpredictable values.

Overview

FunctionDescriptionSignature
e_randGenerate encrypted random number(CpiContext, u8) -> Result<Euint128>
The generated random value is encrypted and cannot be predicted or known until decrypted by an authorized party.

Basic Usage

The second parameter identifies whether the operand is ciphertext (0) or plaintext (1). Always pass 0 when working with encrypted handles.

Account Structure

Use Cases

Fair Lottery Selection

Random Game Outcomes

Security Properties

  • Unpredictable: Random values cannot be predicted before generation
  • Encrypted: Results are encrypted and only visible to authorized parties
  • Verifiable: Decryption requires attestation from the covalidator network
The random value remains encrypted until decryption is requested. Ensure proper access control is set up before allowing decryption of random values in sensitive applications.