thornik

Bench 'random' for D

Dec 5th, 2017
615
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×