> For the complete documentation index, see [llms.txt](https://docs.triumpharcade.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.triumpharcade.com/triumph-sdk/triumph-rng.md).

# Triumph RNG

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

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.&#x20;

<div align="center"><figure><img src="/files/ASOZGKmjFdstCAiMiF92" alt=""><figcaption><p>Random number synchronization ensures fair gameplay in games with limited amounts of randomness.</p></figcaption></figure></div>

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).&#x20;

Below is an example from our flagship game.&#x20;

{% tabs %}
{% tab title="Unity" %}

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

{% endtab %}

{% tab title="Swift" %}

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

{% endtab %}
{% endtabs %}
