Here is an article about optimization http://www.javaworld.com/javaworld/jw-04-1997/jw-04-optimize.html?page=1
What you are talking about is a lookup table for your random numbers. In most cases, this happens faster, but in this case it will also change the results.
In general, my approach always finds the one that takes the most time, and research it as deep as I can. Make sure you're not doing too much work, and look at things that seem strangely slow. Optimized code usually spends most of the time on basic math operations. Try to keep going until it looks like you spend most of your time only in mathematical operations.
Your code is doing something, and there may be a better way to do this. So keep your ear on the ground for a better algorithm.
And keep in mind, there are all kinds of Android devices. It will be difficult to optimize for all of them. Sometimes you have to make a solid run during optimization, and then assume that itβs as good as it is going to get and start to reduce the amount of work performed or decide that it is simply impossible.
source share