Triumph Docs
  • 🏆Triumph Tournaments
  • Triumph SDK
    • Install Triumph
    • Import Triumph
    • Presenting Triumph
    • Triumph Lifecycle
    • Triumph RNG
    • Configuration
    • Keys and Permissions
    • Apple Pay
    • Go Live Checklist
    • Test Flight Build
    • App Store Submission
    • Get Paid!
    • Demo Integrations
      • Swift Example
      • Unity Example
    • Common Errors
      • Unity
        • .NET Error
        • Enable Bitcode Error
  • Requirements
    • Apple Business Developer Account
  • Privacy Policy Multi Product
  • Terms of Use
  • Frequently Asked Questions (Regulatory and Legal)
  • Responsible Gaming Policy
  • Cookie Policy
  • Opt Out of Sale or Sharing of Information
Powered by GitBook
On this page
  1. Triumph SDK

Triumph RNG

Estimated Time: 15 minutes.

PreviousTriumph LifecycleNextConfiguration

Last updated 1 year ago

To minimize elements of chance in games with randomness, we want to synchronize randomness between users playing in a given match.

As an example, in our flagship brick breaker game, the configuration of bricks in each level is random. When two users play, we want them to have the same exact grid.

First, identify any sources of randomness in your game. This would be in places where you use normal random number libraries. You must replace these sources of randomness with the Triumph function getNextRandom , which returns a synchronized random number in (0,1).

Below is an example from our flagship game.

using TriumphSDK;

public class GameController : MonoBehaviour {
    public void generateBlocks() 
    {
        // There are 8 columns to generate blocks in
        for col in 1..<8 {
            // Triumph.getNextRandom() will give a seeded uniform 
            // random variable in (0,1). Since we want a random bool, we just 
            // check if this random is >= 0.5, which will happen 50 percent
            // of the time in expectation. 
            let triumphRandomSyncBool = Triumph.GetRandom() >= 0.5
            
            // Old implementation
            // if Bool.random() {
             
            // New implementation
            if triumphRandomSyncBool { 
                addBlock(inColumn: col)
            }
        }
    }
}
import TriumphSDK

class YourGameViewController {
    // There are 8 columns to generate blocks in
    func generateBlocks() {
        for col in 1..<8 {
        
            // Triumph.getNextRandom() will give a seeded uniform 
            // random variable in (0,1). Since we want a random bool, we just 
            // check if this random is >= 0.5, which will happen 50 percent
            // of the time in expectation. 
            let triumphRandomSyncBool = Triumph.nextRandom() >= 0.5
            
            // Old implementation
            // if Bool.random() {
             
            // New implementation
            if triumphRandomSyncBool { 
                addBlock(inColumn: col)
            }
        }
    }
}
Random number synchronization ensures fair gameplay in games with limited amounts of randomness.