Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.     Pythia - True random number generator
  4.  
  5.     File name: pythia.js (Version: 0.1)
  6.     Description: This file contains the Pythia - True random number generator.
  7.    
  8.     Coded by George Delaportas (G0D)
  9.    
  10.     Copyright © 2014
  11.  
  12. */
  13.  
  14.  
  15.  
  16. // Pythia
  17. function pythia()
  18. {
  19.  
  20.     var self = this;
  21.  
  22.     function utilities()
  23.     {
  24.  
  25.         this.loop = function(__this_result)
  26.         {
  27.  
  28.             var __results_length = results.length;
  29.  
  30.             if (__results_length === 0 || __this_result >= results[__results_length - 1])
  31.             {
  32.  
  33.                 if (__this_result >= max_random_num)
  34.                     return self.generate();
  35.  
  36.                 else
  37.                 {
  38.  
  39.                     if (__this_result === results[__results_length - 1])
  40.                     {
  41.  
  42.                         __this_result++;
  43.  
  44.                         results.push(__this_result);
  45.  
  46.                     }
  47.  
  48.                     else
  49.                         results.push(__this_result);
  50.  
  51.                     return __this_result;
  52.  
  53.                 }
  54.  
  55.             }
  56.  
  57.             for (var i = 0; i < __results_length; i++)
  58.             {
  59.  
  60.                 if (__this_result === results[i])
  61.                     __this_result++;
  62.  
  63.                 else
  64.                 {
  65.  
  66.                     if (__this_result < results[i])
  67.                     {
  68.  
  69.                         results.splice(i, 0, __this_result);
  70.  
  71.                         break;
  72.  
  73.                     }
  74.  
  75.                 }
  76.  
  77.             }
  78.  
  79.             return __this_result;
  80.  
  81.         };
  82.  
  83.     }
  84.  
  85.     this.generate = function()
  86.     {
  87.  
  88.         var __this_result = Math.floor((Math.random() * max_random_num) + 1);
  89.  
  90.         __this_result = utils.loop(__this_result);
  91.  
  92.         return __this_result;
  93.  
  94.     };
  95.  
  96.     this.reset = function()
  97.     {
  98.  
  99.         results = [];
  100.  
  101.         return true;
  102.  
  103.     };
  104.  
  105.     var max_random_num = 9007199254740992,
  106.         results = [],
  107.         utils = new utilities();
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement