icekontroi

Generator Class 2.0

Jan 5th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. package scripts.ReactionTime;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Generator {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. for (int a = 0; a < 100000; a++) {
  10. System.out.println(getBankOpenReaction());
  11. }
  12. }
  13.  
  14. private static Random r = new Random();
  15.  
  16. public static double nextGaussian(double avg, double dev) {
  17.  
  18. return avg + r.nextGaussian() * dev;
  19. }
  20.  
  21. public static double nextExponential(double clustering) {
  22.  
  23. return -Math.log(1 - r.nextDouble()) / clustering;
  24. }
  25.  
  26. public static double nextExGaussian(double avg, double dev, double clustering) {
  27.  
  28. return nextGaussian(avg, dev) + nextExponential(clustering);
  29. }
  30.  
  31. public static double nextUniform(double minimum, double maximum) {
  32.  
  33. return r.nextDouble() * (maximum - minimum) + minimum;
  34. }
  35.  
  36. /**
  37. * Utility function to generate a reaction time within a given set of parameters.
  38. * @param avg The average (mu) of the data.
  39. * @param dev The standard deviation (sigma) of the data.
  40. * @param clustering How tightly clustered the data will be about the mean. Smaller values reduce clustering, while larger ones increase it.
  41. * @param leftSkew The strength at which the values will be skewed to the left.
  42. * @param minimum The minimum in the range of values that can be produced.
  43. * @param maximum The maximum in the range of values that can be produced.
  44. */
  45. public static double nextReactionTime(double avg, double dev, double clustering, double leftSkew, double minimum, double maximum) {
  46.  
  47. double next = r.nextDouble();
  48.  
  49. if (next < leftSkew) {
  50. return nextUniform(minimum, maximum);
  51. }
  52.  
  53. double exGaussian = nextExGaussian(avg, dev, clustering);
  54. if (exGaussian < minimum || exGaussian > maximum) {
  55. return nextReactionTime(avg, dev, clustering, leftSkew, minimum, maximum);
  56. }
  57.  
  58. return exGaussian;
  59. }
  60.  
  61. // REACTION TIME GENERATORS
  62.  
  63. public static long getBankOpenReaction() {
  64.  
  65. return Math.round(nextReactionTime(275, 70, 0.007, 0.0025, 100, 1700));
  66. }
  67. }
Add Comment
Please, Sign In to add comment