Mario Kart 64 has a 2 byte unsigned int random number generator (RNG) that constantly updates every frame in the game. This can be queried by Gameshark conditional (D) codes to cause the codes to execute memory writes to trigger events probabilisticly.

Mario Kart 64's RNG is the same as Super Mario 64's RNG. This video explains how the RNG works https://www.youtube.com/watch?v=MiuLeTE2MeQ

The RNG memory address:

802BA290

The 1 byte version RNG activation code triggers a random event about once every 10 seconds:

D02BA290 00??
8??????? ????

The 2 byte version RNG activation code triggers a random event about 1-2 times per hour:

D12BA290 ????
8??????? ????

Multiple activators with the same 80 or 81 memory write but pointing to different RNG values with the D0 or D1 conditional will increase the chance of an event occurring.

Note that the RNG initializes to the value of the selected character (Mario = 0x0000) at the start of a Grand Prix cup.