Page 2 of 2

Re: Help with C++ Code to Flowcode Conversion

Posted: Sun Oct 17, 2021 4:16 pm
by mnfisher
Random in Flowcode returns a value between 0 and 0xFFFF
To 'clamp' it to -2..2

Code: Select all

.hSkew = (random() % 5) - 2
should do what you need

% operator is mod (modulus) - so random() % 5 will return a number in the range 0..4 then -2 gives -2 .. 2

Martin

Re: Help with C++ Code to Flowcode Conversion

Posted: Sun Oct 17, 2021 6:47 pm
by unity-control
Excellent Martin, thanks for all of this! It is all very clearly explained.

Cheers!
R

Re: Help with C++ Code to Flowcode Conversion

Posted: Sun Oct 17, 2021 7:02 pm
by mnfisher
Oop - just thought of a problem with the random code.

If random generates a negative number I'm not sure if the remainder can be negative (some testing might be in order)

If it can you'll need

... = (random() & 0x7fff) % 5 ... To clear the sign bit.

Martin

Re: Help with C++ Code to Flowcode Conversion

Posted: Tue Oct 19, 2021 6:02 pm
by unity-control
Understood Martin, thanks for ALL your comments.

R