From 3cbf850ab6e664eed6afe709cbea47f4c9584dd1 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Tue, 9 Oct 2012 13:55:22 -0700 Subject: [PATCH] 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 --- cmds/monkey/src/com/android/commands/monkey/Monkey.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmds/monkey/src/com/android/commands/monkey/Monkey.java b/cmds/monkey/src/com/android/commands/monkey/Monkey.java index c8a480fd6..5e86a79c8 100644 --- a/cmds/monkey/src/com/android/commands/monkey/Monkey.java +++ b/cmds/monkey/src/com/android/commands/monkey/Monkey.java @@ -516,6 +516,10 @@ public class Monkey { mMainCategories.add(Intent.CATEGORY_MONKEY); } + if (mSeed == 0) { + mSeed = System.currentTimeMillis() + System.identityHashCode(this); + } + if (mVerbose > 0) { System.out.println(":Monkey: seed=" + mSeed + " count=" + mCount); if (mValidPackages.size() > 0) { @@ -550,8 +554,7 @@ public class Monkey { return -4; } - mRandom = new SecureRandom(); - mRandom.setSeed((mSeed == 0) ? -1 : mSeed); + mRandom = new Random(mSeed); if (mScriptFileNames != null && mScriptFileNames.size() == 1) { // script mode, ignore other options