Advertisement
thornik

Bench 'random' for D

Dec 5th, 2017
2,563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.47 KB | None | 0 0
  1. // ldc2.exe -release -m64 -O randomd.d
  2.  
  3. import std.stdio;
  4. import std.conv;
  5.  
  6. const int IM = 139968;
  7. const int IA = 3877;
  8. const int IC = 29573;
  9.  
  10. double gen_random(double max)
  11. {
  12.     static int last = 42;
  13.     last = (last * IA + IC) % IM;
  14.     return max * last / IM;
  15. }
  16.  
  17. void main(string[] args)
  18. {
  19.     ulong n = args.length < 2 ? 1 : to!ulong(args[1]);
  20.     double result = 0;
  21.    
  22.     while (n--)
  23.         result = gen_random(100.0);
  24.  
  25.     writeln(result);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement