Random Zero Results

In general, do any multiplications BEFORE doing any divisions, and ensure your variable type can fit the product without overflowing. Since 1024 is 210, you need at least 20 bits for 1024*1024, bigger than a 16-bit int but well within the range of a 32-bit long.

(int)( (long)analogRead(red_in) * (long)i / 1023)