Help with C++ Code to Flowcode Conversion

For general Flowcode discussion that does not belong in the other sections.
mnfisher
Valued Contributor
Posts: 938
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: Help with C++ Code to Flowcode Conversion

Post 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

unity-control
Posts: 52
Joined: Wed Sep 08, 2021 10:36 pm
Has thanked: 26 times
Been thanked: 11 times

Re: Help with C++ Code to Flowcode Conversion

Post by unity-control »

Excellent Martin, thanks for all of this! It is all very clearly explained.

Cheers!
R

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: Help with C++ Code to Flowcode Conversion

Post 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

unity-control
Posts: 52
Joined: Wed Sep 08, 2021 10:36 pm
Has thanked: 26 times
Been thanked: 11 times

Re: Help with C++ Code to Flowcode Conversion

Post by unity-control »

Understood Martin, thanks for ALL your comments.

R

Post Reply