Increment Number Based on Boolean Value

I want to increment a field based on a random boolean value generated. I tried using a sequence and adding a formula on the sequence to only increment when the boolean was true. This didn’t work.

I tried using the formula field type and creating a lambda but again I could not get it to work.

Here is what I have tried.

but don’t know how to control the increment value conditionally.

Can anyone give me some pointers on what to do? Is there a way to create a global value and increment that and return it in the sequence field?

Cheers for any help
Jim