Search code examples
apex-code

How to set the seed for Math.random() in Apex


Is there a way to set the seed for the random number generator in Apex? And if so; which function do I use for it?


Solution

  • It likely isn't possible to seed the RNG in Apex. If you need a repeatable sequence of random numbers, you'll have to implement a seeded pseudo random number generator yourself.

    On the Apex platform, I'm sure they have a huge source of entropy available to generate random numbers, and there's no need for you to seed the generator.