ActivitySim Random Number Generation
Investigating ways to make Explicit Error Terms run faster
May 5, 2026
Agenda
2
RNGs are used to make decisions
3
Mode | Utility | Exp(Utility) | Probability | Cumulative Probability |
SOV | -1.6 | 0.2070 | 0.5501 | 0.5501 |
HOV | -2.2 | 0.1136 | 0.3019 | 0.8520 |
Transit | -2.9 | 0.0557 | 0.1480 | 1.0000 |
Sum | | 0.3763 | 1.0000 | |
> 0.6721 ?
Random Number Draw = 0.6721
Chosen Mode = HOV
Explicit Error Terms Requires Many More RNG Draws
4
Mode | Utility | Exp(Utility) | Probability | Cumulative Probability | Explicit Error Term | Total Utility + EET |
SOV | -1.6 | 0.2070 | 0.5501 | 0.5501 | -0.2 | -1.8 |
HOV | -2.2 | 0.1136 | 0.3019 | 0.8520 | 0.5 | -1.7 |
Transit | -2.9 | 0.0557 | 0.1480 | 1.0000 | 0.1 | -2.8 |
Sum | | 0.3763 | 1.0000 | | | |
Now drawing random number for every alternative
For 2-zone location choice models, the number of draws grows very fast!
EET Reminder – EET leads to more stable results
5
Properties of ActivitySim’s RNG
6
Current Random Number Generator
7
Performance Testing – Drawing Random Numbers
8
Performance Testing – Reseed and Draw Same Number
9
Performance Testing – Reseed + offset + many draws
10
Random Numbers in Location Choice
Location Choice Flow for 2-zone using EET
11
Total: C(TS + S + M)
For something like SANDAG where
C = 500k workers
T = 6k TAZs
S = 30 samples
M = 30k MAZs
Total = 1.05x10^11
105 billion draws!
Results Calling ActivitySim’s actual RNG generators
12
Calculated with 1,000 choosers
Calculated with 6k TAZs
and 4 MAZs per TAZ
Reseeding is slow – Can we get around it?
Use a hash-based, “stateless” random number generator
Start with: (global seed & chooser ID & model) + alt_id + offset
Combine this into a single 64-bit integer as our new “state”:
Scramble this integer with a fast hash mixer that: shifts bitx, xors bits, multiplies by large constant
Converts the hashed 64 bit into a uniform number between 0 and 1:
draw = top 53 random-looking bits / 253
Convert to Gumbel by
g = -log(-log(draw)
13
Ok, hashed approach is fast for ActivitySim, but does it work?
14
Next Steps
15