1 /******************************************************************************* 2 * Copyright (c) 2000, 2006 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.team.tests.ccvs.ui.benchmark; 15 16 17 import java.util.Random; 18 19 /** 20 * Encapsulates algorithms and state for generating deterministic sequences. 21 * The sequence of numbers generated will always follow the same pattern, 22 * regardless of the time, place, or platform. 23 */ 24 public class SequenceGenerator { 25 private static long globalSeqNum = System.currentTimeMillis() * 1000; 26 private final Random random; 27 private int uniqueInt; 28 29 /** 30 * Constructs a new sequence generator with a known seed. 31 */ SequenceGenerator()32 public SequenceGenerator() { 33 random = new Random(3141592653589793238L); // a known constant 34 uniqueInt = 1000000; 35 } 36 37 /** 38 * Returns a globally unique long integer. 39 */ nextGloballyUniqueLong()40 public static long nextGloballyUniqueLong() { 41 return globalSeqNum++; 42 } 43 44 /** 45 * Returns a unique 7-digit integer. 46 */ nextUniqueInt()47 public int nextUniqueInt() { 48 return uniqueInt++; 49 } 50 51 /** 52 * Returns a pseudo-random integer between 0 and n-1. 53 * @see Random#nextInt(int) 54 */ nextInt(int n)55 public int nextInt(int n) { 56 return random.nextInt(n); 57 } 58 59 /** 60 * Returns a pseudo-random real number following a gaussian distribution. 61 * @see Random#nextGaussian() 62 */ nextGaussian()63 public double nextGaussian() { 64 return random.nextGaussian(); 65 } 66 } 67