Triumph RNG

Estimated Time: 15 minutes.

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)
            }
        }
    }
}

Last updated