generate_random_CBN(n,s, p) :
create n Boolean variables X1, . . . , Xn Let S **= {{}**, Xi : i ≤ i ≤ n}
{S is a set of context-variable pairs}
repeat choose random -c, Xi ∈ S
choose random j such that 1 ≤ j < n if j < i and Xj doesn't appear in c:
replace -c, Xi ∈ S with c ∧ Xj = *true*, Xiand c ∧ Xj = *false*, Xi until there are n + s elements of S
for each -c, Xi ∈ S
Let V = {Xi}
for each j < i if Xj doesn't appear in c with probability p add Xjto V
create a random table T on the variables in V
add confactor -c, T to the contextual belief network Figure 16: Algorithm for constructing the randomised examples confactor with probability p. The variable that the leaf is for is also in the confactor. We assign random numbers the probabilities (these numbers won't affect anything in the results assuming that the times for operations on floating point numbers isn't affected by the actual values of the numbers).

The algorithm to construct the random examples used in Section 6.2 is given in Figure 16. Note that "choose random" means to choose randomly from a uniform distribution.

For the examples biased towards using fewer variables, we replaced the line:
replace -c, Xi ∈ S with c ∧ Xj = *true*, Xiand c ∧ Xj = *false*, Xi with if there is k < i such that Xk doesn't appear in c and Xk is used in another context then replace -c, Xi ∈ S with -c ∧ Xk = *true*, Xi and -c ∧ Xk = *false*, Xi else replace -c, Xi ∈ S with c ∧ Xj = *true*, Xiand c ∧ Xj = *false*, Xi where, if more than one such k exists, the k is chosen uniformly from all of the values that satisfy the condition.

Figure 17 shows some of the details of some of the data shown in Figure 11. All of the times are for a Java implementation running on a 700 MHz Pentium running Linux with 768 megabytes of memory. In order to allow for the variation in run times due to garbage collection, each evaluation was run three times and the smallest time was returned.

For each generated example, the table of Figure 17 shows
- n the number of variables