Random


random()

Returns a number between 0 and 1. If setSeed has been called, it uses the sfc32 algorithm, otherwise it defaults to the browser's implementation of Math.random().

JavaScript
Python
function behavior(state, context) {
  if (hstd.random() > 0.5) {
    // do something
  }
}

setSeed(s: string)

Sets a seed for the random number generator used in hash_stdlib.random() and in any stochastic function in hash_stdlib.stats. The seed will apply across all behaviors and agents within a simulation run.

JavaScript
Python
function behavior(state, context) {
  if (state.timestep == 1) {
    // If it's the first timestep, set the initial seed of the sim.
    hstd.setSeed("initial_seed");
  }
  const num_new_agents = hstd.stats.poisson.sample(10); // will return the same sample every run
}

Previous

Join our community of HASH developers