/* average run of alternating coin-flips */ /* using a HASH_ARRAY type */ make_random_state(true)$ for j : 0 thru 999 do ( old_coin : 0, /* not 'heads' or 'tails' */ new_coin : random(2)+1, XX[j] : 0, /* set j-th element to zero */ while new_coin # old_coin do ( old_coin : new_coin, new_coin : random(2)+1, XX[j] : XX[j] + 1 ) )$ load('descriptive)$ float(mean(makelist(XX[j],j,0,999)));