In my problem, I have a lattice with a stochastic cellular automaton. In order to simplify a bit, let's say it is 1D. In my system, each node can be type A, B or C. A way to represent the system and operate fast over it is using an integer 64-bit variable, working bitwise.
Let me give an example of implementation for a system with 4 nodes. Let's say I have that nodes 0 and 3 are in state A, node 1 is in B, and 2 is in C, then:
A -> 1001 -> A = 9 B -> 0100 -> B = 4 C -> 0010 -> C = 2
You see that 3 integers can represent the whole state of the system. I can update the system with a single bit-wise operation. This is used a lot in cellular automatons.
But, now, suppose I have reactions such as
I want to simulate this reactions in a synchronous way using a discrete time $\Delta t$. I can obtain the number of B individuals in the next timestep with:
B = A && r
where $r$ is a random number such that the bit at position $j$ is 1 with probability $p_j=1-\exp(-\mu\Delta t\cdot b_j)$, where $b_j$ is the number of B neighbours of individual $j$. This is, it is 1 with the probability of executing reaction 1.
My question is: is there an efficient method to obtain $r$?