📑
TOMB
  • 👋Tomb
  • 🎆Quick Start
  • Getting Set up
    • 🛠️Setup
  • Basics
    • 🚩Basics
      • Default types
        • Available macros
      • Variable declaration
      • Call method
      • Library Importing
      • Trigger's
      • Properties
  • Features
    • ✨Features
  • Libraries
    • 📚Libraries
      • Call
      • Runtime
      • Math
      • Token
      • NFT
      • Account
      • Organization
      • Oracle
      • Storage
      • Array
      • Utils
      • Leaderboard
      • Market
      • Crowdsale
      • Stake
      • Governance
      • Relay
      • Mail
      • Time
      • Task
      • UID
      • Map
      • List
      • String
      • Decimal
      • Enum
      • Address
      • Module
      • Format
  • Examples
    • 🖥️Examples
      • Simple Sum
      • Conditions
      • Switch case
      • Simple Counter
      • Counter per Address
      • Strings
      • Decimals
      • Enums
      • Map support
      • Array example
      • Random numbers
      • Tokens
        • Fungible Token
      • Scripts
      • Inline asm
      • Custom Events
      • Triggers Example
        • Trigger OnMint
        • Trigger OnBurn
        • Trigger OnWrite
        • Trigger OnInfuse
        • Trigger OnSeries
        • Trigger OnUpgrade
        • Trigger OnMigrate
        • Trigger OnReceive
        • Trigger OnSend
        • Trigger OnKill
      • Methods variables
      • Type interface in variable declarations
      • Tasks
      • Calls
      • NFTs
      • Multiple returns
  • Tutorials
    • 📹Tutorials
  • Resources
    • 👻Getting Started
    • 👻About Phantasma
    • 🧑‍🤝‍🧑For new Soldiers
    • 👨‍💻For Developers
Powered by GitBook
On this page
  1. Examples
  2. Examples

Random numbers

It is possible to generate pseudo random numbers, and also to control the generation seed. If a seed is not specified, then the current transaction hash will be used as seed, if available.

contract test {
	import Random;

	global my_state: number;

	constructor(owner:address)
	{
		Random.seed(16676869); // optionally we can specify a seed, this will make the next sequence of random numbers to be deterministic
		my_state = mutateState();
	}

	public mutateState():number
	{
		my_state = Random.generate() % 1024; // Use modulus operator to constrain the random number to a specific range
		return my_state;
	}
}
PreviousArray exampleNextTokens

Last updated 2 years ago

🖥️