Skip to content

Commit

Permalink
don't dispense the same random number twice in a row, otherwise 1/100…
Browse files Browse the repository at this point in the history
… test runs will fail

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2081 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
sbryzak committed Mar 18, 2009
1 parent 694272b commit e20cc46
Showing 1 changed file with 9 additions and 2 deletions.
Expand Up @@ -6,15 +6,22 @@
@ApplicationScoped
public class Generator {

private int lastInt = 0;
private java.util.Random random = new java.util.Random( System.currentTimeMillis() );

java.util.Random getRandom()
{
return random;
}

@Produces @Random int next() {
return getRandom().nextInt(100);
@Produces @Random int next() {
int nextInt = getRandom().nextInt(100);
while (nextInt == lastInt)
{
nextInt = getRandom().nextInt(100);
}
lastInt = nextInt;
return nextInt;
}

}

0 comments on commit e20cc46

Please sign in to comment.