Quantcast
Channel: stardot.org.uk
Viewing all articles
Browse latest Browse all 2392

programming • Re: RND

$
0
0
It is interesting to see how different ways to do the same thing take different amounts of time. Though I am only doing the calculation once per run so timing of the random number choice isn't critical.
1+ABS RND MOD n% is probably the fastest as, after the 1+, it doesn't stack anything, it's purely evaluating the result of a reault of a result of a result. The others all have binary operations which requires: evalute something, save it for later, evaluate another something, get the previous somethingn back and combine.
I think in some cases INT isn't required, because I store the result in a resident integer variable, which as far as I understand it, has the effect of automatically INTing the value being stored.
There's no difference with positive numbers (within the integer range), but you will see a difference with negative numbers. INT rounds down but casting rounds to zero. INT(-PI) gives -4 but A%=-PI gives -3.

Statistics: Posted by jgharston — Mon Sep 30, 2024 12:02 am



Viewing all articles
Browse latest Browse all 2392

Trending Articles