1 of 7

ActivitySim Random Number Generator

Updating the RNG for use in Explicit Error Terms -- Introduction

Last Updated: March 2026

2 of 7

EET Work Pointed to Need for RNG Improvements

Running with Explicit Error Terms requires many more random number draws

  • Non-EET location choice workflow:
    • Calculate utilities for each destination
    • Exponentiate utiltiies and normalize to convert to probabilities
    • Sample one random number between 0 and 1 to select choice
  • EET location choice workflow:
    • Calculate utilities for each destination
    • Randomly sample random number for explicit error term for each destination
    • Select alternative with highest utility

  • What this means:
    • 1 random draw per chooser for non-EET
    • 30k random draws per chooser (or however many zones the model has) for EET
    • Number of random draws while running with EET can be 30,000x higher!
    • EET runtimes were drastically longer for models with many alternatives

2

3 of 7

ActivitySim has Specific Requirements for its RNG

  • Reseeding by chooser and model step:
    • Each household, person, tour, trip gets its own repeatable random stream based on its ID (aka chooser ID)
    • Allows for random number draws to be consistent regardless of number of households run in the simulation, multi-process or single process, etc.
    • Calculate utilities for each destination
    • Exponentiate utilities and normalize to convert to probabilities
    • Sample one random number between 0 and 1 to select choice
  • Offsets – tracks how far each chooser has progressed in its random stream
    • Offset value is the is next position in a chooser’s stream
    • Avoids reusing the same random numbers
  • Global Seed – a base seed all other seeds are starting from
    • Supports repeatability and scenario testing
    • Helps to understand model stochasticity
  • Random draws – needs to actually generate random numbers!
    • Needs to generate uniform random numbers, normal/lognormal values, and select choices from alternatives

3

4 of 7

Starting to look at RNG Options and Build Tests

4

Option

How it works

Pros

Cons

RandomState

ActivitySim's current option: Uses NumPy’s older random engine. For each chooser, it resets to that chooser’s seed, then draws numbers.

Familiar, stable, easy to trust

Older/slower than newer methods

GeneratorPCG64

Uses NumPy’s newer Generator with PCG64. Also reseeds per chooser before drawing.

Modern default quality, reproducible, clearer future path than RandomState

Still does a lot of per-chooser setup, so not the fastest

GeneratorSFC64

Same style as above but uses the SFC64 engine.

Often very fast, reproducible

Results differ from PCG64, and speed can vary by workload

GeneratorPhilox

Same style but uses Philox engine.

Strong reproducibility, good parallel-friendly design

May not be fastest for your specific workload

GeneratorMT19937

Same style but uses Mersenne Twister engine.

Very well-known and widely used historically

Not the most modern choice, can be slower than newer engines

PhiloxAdvance

Philox-based approach that can jump ahead when offset is used, instead of stepping one-by-one.

Better behavior when fast-forward/offset is large; reproducible

More specialized; may not always beat simpler options

VectorizedChooserHash

Uses a fast “hash-like” method that generates numbers for many choosers at once, while keeping each chooser independent of others.

Very fast for batch work, seed-invariant by chooser, supports both replacement and non-replacement choice

Not a standard NumPy engine like PCG64/Philox; different statistical style than those families

5 of 7

Building Evaluation Tool to Compare RNGs

  • Reseeding:
    • Follows ActivitySim’s need to tie random numbers to individual chooser IDs
  • Consistency testing:
    • Checks that one chooser’s random results do not change just because other choosers are added, removed, or reordered.
  • Realistic model workload:
    • Benchmark is structured like location choice, where the model reseeds for a chooser and then generates draws.
    • Makes the test representative of actual ActivitySim use.
  • Performance measurement:
    • Tracks runtime and memory use as the number of reseeds or random draws increases.
    • Shows which RNG options scale best.

5

6 of 7

Preliminary Results

RNG performance is a trade-off between reseeding speed and sampling speed

7 of 7

Next Steps

Just getting started

  • Finish building evaluation script
    • Finalize what metrics and structure we care about
    • Build in offset functionality
  • Fully explore random number options
  • Consider structural improvements to how ActivitySim handles random numbers beyond just the generator itself
  • Provide a recommendation on approach to consortium

7