Skip to content

Commit 3cbf850

Browse files
committed
Make all monkeys do the same thing
Monkeys were using SecureRandom, but what it really wanted was an LCRNG that allowed it to reproduce the same output with seeds. This change allows the monkeys to shine. Bug: 6950454 Change-Id: Iabf0fc5e7d50b786fa32b946e85de797220ff569
1 parent 41ee0fd commit 3cbf850

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

cmds/monkey/src/com/android/commands/monkey/Monkey.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,10 @@ private int run(String[] args) {
516516
mMainCategories.add(Intent.CATEGORY_MONKEY);
517517
}
518518

519+
if (mSeed == 0) {
520+
mSeed = System.currentTimeMillis() + System.identityHashCode(this);
521+
}
522+
519523
if (mVerbose > 0) {
520524
System.out.println(":Monkey: seed=" + mSeed + " count=" + mCount);
521525
if (mValidPackages.size() > 0) {
@@ -550,8 +554,7 @@ private int run(String[] args) {
550554
return -4;
551555
}
552556

553-
mRandom = new SecureRandom();
554-
mRandom.setSeed((mSeed == 0) ? -1 : mSeed);
557+
mRandom = new Random(mSeed);
555558

556559
if (mScriptFileNames != null && mScriptFileNames.size() == 1) {
557560
// script mode, ignore other options

0 commit comments

Comments
 (0)