Comment Re:When you count from 1 to 10, do you stop at 9? (Score 1) 198
This is crap. Either 'toIndex' actually means 'onePastToIndex', or the final if test should be if (toIndex >= arrayLen) .
Try calling this function with arrayLen=10, fromIndex=1, toIndex=10 -- no exception, despite the zero-based array's last element being index 9.
If you ask somebody to count from 1 to 10, do they stop at 9?
If you see the following prototype: int randomValue( int fromValue, int toValue), what is the highest value you would expect could be returned?
Identifiers should be named accurately! Bad identifiers like this make code unnecessarily difficult to read, and makes it easier for bugs to go unnoticed.
If the allegation is that Google copied this code, and they've replicated the bad names along with the trivial algorithm, it does seem likely they authored their version via cut & paste...
It might actually be correct, it depends on what's calling this method.
For example take either String.substring(begin,end) or String.subSequence(begin,end)
In either of those methods begin is the first inclusive index but end is the last exclusive one , so when you want chars 1..9 then begin is 1 but end is 10
There's plenty of api call's in there which follow the same pattern.