mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
20 lines
807 B
HTML
20 lines
807 B
HTML
<html>
|
|
<body>
|
|
Reports calls to <code>Math.random()</code> which are immediately
|
|
cast to <code>int</code>.
|
|
<p>Casting a <code>double</code> between <code>0.0</code> (inclusive) and
|
|
<code>1.0</code> (exclusive) to <code>int</code> will always round down to zero. The value
|
|
should first be multiplied by some factor before casting it to an <code>int</code> to
|
|
get a value between zero (inclusive) and the multiplication factor (exclusive).
|
|
Another possible solution is to use the <code>nextInt()</code> method of
|
|
<code>java.util.Random</code>.</p>
|
|
<p><b>Example:</b></p>
|
|
<pre><code> <b>int</b> r = (<b>int</b>)Math.random() * 10;
|
|
</code></pre>
|
|
<p>After the quick fix is applied:</p>
|
|
<pre><code> <b>int</b> r = (<b>int</b>)(Math.random() * 10);
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
</body>
|
|
</html>
|