For general Flowcode discussion that does not belong in the other sections.
-
mnfisher
- Valued Contributor
- Posts: 1460
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 709 times
Post
by mnfisher »
Random in Flowcode returns a value between 0 and 0xFFFF
To 'clamp' it to -2..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
-
mnfisher
- Valued Contributor
- Posts: 1460
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 709 times
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