Advertisement
Jenssile

Random using time again

Oct 23rd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1.         static void Main(string[] args)
  2.         {
  3.             Console.WriteLine(randomz());
  4.  
  5.             static int randomz()
  6.             {
  7.                 // this is not 100% random this is what is called sudo random,
  8.                 // even then if this is run more than once to fast you will get duplicats.
  9.                 // but running this every now and then and it will be as good as random.
  10.  
  11.                 DateTime dateTime = DateTime.Now; // get the datetime of now. (when run)
  12.                 double deciaml = (double)dateTime.TimeOfDay.TotalMilliseconds;
  13.                     // convert that datetime to a decimal number (in total milliseconds).
  14.                 int integer = (int)dateTime.TimeOfDay.TotalMilliseconds;
  15.                     // convert that datetime to an integer (in total milliseconds).
  16.                 double dif = ((integer / 100) - (deciaml / 100)) * 100; // do mathy stuff.
  17.                 dif = Math.Abs(dif); // remove the decimals and make it an absolute value
  18.                 int num = Convert.ToInt32(dif); // convert that absolute value to an int 32.
  19.                 return num;
  20.             }
  21.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement