I want to generate a spread of random number from 0 to 3, but this spread must respect the rules:
NO (1 after 3)
NO (3 after 1)
NO (0 after 2)
NO (2 after 0)

means, 1 cannot be immediately after 3, nor can be 3 after 1, and the same for 2 and 0
i.e. this is allowed: (0,1,0,3,2,1,0,1,1,1,0,…etc)
this is wrong: (0,2,0,0,1,3,0,1,3,…etc)

I tried everything but there is always some small probability to breack the rules… ideas?

when reading this I again think about how nice it would be to have some kind of prolog interpreter package.

so it would be very easy to implement your needed behavior as it would be nothing more than writing your rules in prolog notation and letting the http://en.wikipedia.org/wiki/Warren_Abstract_Machine work for you :)

not fully checked, but the patch does what you need.

edit for the ones who are too lazy to open the patch:
the solution proposed is not use the randomspread not as values directly but as differences between the slices.
since the posted rule is to disallow subsequent slices with a difference of ±2.
so the randomspread ranges between -3 and 3, ±2 are switched out and replaced -> integral -> mod to keep the values between 0 and 3