You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Dawid Weiss (JIRA)" <ji...@apache.org> on 2012/06/15 17:04:43 UTC

[jira] [Commented] (LUCENE-4148) _TestUtil should be able to generate random longs

    [ https://issues.apache.org/jira/browse/LUCENE-4148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13295713#comment-13295713 ] 

Dawid Weiss commented on LUCENE-4148:
-------------------------------------

Try RandomInts from randomizedtesting, it does what you need:
{code}
  /** 
   * A random integer from <code>min</code> to <code>max</code> (inclusive).
   */
  public static int     randomIntBetween(Random r, int min, int max) {
    assert max >= min : "max must be >= min: " + min + ", " + max;
    long range = (long) max - (long) min;
    if (range < Integer.MAX_VALUE) {
      return min + r.nextInt(1 + (int) range);
    } else {
      return min + (int) Math.round(r.nextDouble() * range);
    }
  } 
{code}
                
> _TestUtil should be able to generate random longs
> -------------------------------------------------
>
>                 Key: LUCENE-4148
>                 URL: https://issues.apache.org/jira/browse/LUCENE-4148
>             Project: Lucene - Java
>          Issue Type: Improvement
>          Components: general/test
>            Reporter: Adrien Grand
>            Priority: Trivial
>
> It would be helpful in TestPackedInts at least, in order to generate random values (as a workaround, we currently generate a random int between 0 and {{min(Integer.MAX_VALUE, PackedInts.maxValue(bitsPerValue)}}). Moreover, it would help to fix {{nextInt}} for large ranges (calling {{nextInt(random, -10, Integer.MAX_VALUE)}} or even {{nextInt(random, 0, Integer.MAX_VALUE)}} currently fails because the range of values is {{> Integer.MAX_VALUE}}.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org