Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. private void Random()
  2. {
  3. double tmpRand = 0;
  4. double tmpRand1 = 0;
  5. double tmpRand2 = 0;
  6. double S;
  7. Random newRand = new Random();
  8.  
  9. for (int i = 0; i < amount; i++)
  10. {
  11. S = 1;
  12. tmpRand = newRand.NextDouble();
  13. while (S >= 1)
  14. {
  15. tmpRand1 = newRand.NextDouble();
  16. tmpRand2 = newRand.NextDouble();
  17. S = Math.Pow((2 * tmpRand1 - 1), 2) + Math.Pow((2 * tmpRand2 - 1), 2);
  18. }
  19.  
  20. if (tmpRand < cl1.P)
  21. {
  22. GetRandom(tmpRand1, tmpRand2, S, ref cl1);
  23. }
  24. else
  25. {
  26. GetRandom(tmpRand1, tmpRand2, S, ref cl2);
  27. }
  28. }
  29.  
  30. cl1.n = cl1.mas1.Count;
  31. cl2.n = cl2.mas1.Count;
  32.  
  33. cl1.oP = Convert.ToDouble(cl1.n) / Convert.ToDouble(amount);
  34. cl2.oP = Convert.ToDouble(cl2.n) / Convert.ToDouble(amount);
  35.  
  36. CalcError();
  37. cl1.Po = Convert.ToDouble(cl1.cntPo) / Convert.ToDouble(cl1.n);
  38. cl2.Po = Convert.ToDouble(cl2.cntPo) / Convert.ToDouble(cl2.n);
  39. }
  40.  
  41. private void GetRandom(double tmp1, double tmp2, double S, ref Class cl)
  42. {
  43. double X = (2 * tmp1 - 1) * Math.Sqrt(-2 * Math.Log(S) / S);
  44. double Y = (2 * tmp2 - 1) * Math.Sqrt(-2 * Math.Log(S) / S);
  45.  
  46. X = cl.d1 * X + cl.m1;
  47. Y = cl.d2 * Y + cl.m2;
  48.  
  49. cl.mas1.Add(X);
  50. cl.mas2.Add(Y);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement