Add my copyright to files I've modified.
[synfig.git] / synfig-core / trunk / src / synfig / guid.cpp
index bf23475..cfac979 100644 (file)
@@ -2,10 +2,11 @@
 /*!    \file guid.cpp
 **     \brief Template File
 **
-**     $Id: guid.cpp,v 1.4 2005/01/13 06:48:39 darco Exp $
+**     $Id$
 **
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007 Chris Moore
 **
 **     This package is free software; you can redistribute it and/or
 **     modify it under the terms of the GNU General Public License as
@@ -33,6 +34,7 @@
 #endif
 
 #include "guid.h"
+#include "quick_rng.h"
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -76,50 +78,6 @@ using namespace synfig;
 
 /* === M E T H O D S ======================================================= */
 
-// A fast 32-bit linear congruential random number generator
-class quick_rng
-{
-       unsigned long next;
-public:
-       quick_rng(unsigned long seed=0):next(seed) { }
-
-       void set_seed(unsigned long x)
-       {
-               next=x;
-       }
-       
-       unsigned long i32()
-       {
-               static const unsigned long a(1664525);
-               static const unsigned long c(1013904223);
-               
-               return next=next*a+c;
-       }
-
-       unsigned long i16()
-       {
-               return i32()>>16;
-       }
-
-       float f()
-       {
-               static const float m(int(65535));
-               
-               return float(i16())/m;
-       }
-       
-       unsigned long operator()(const unsigned long& m)
-       {
-               if(m==65536)
-                       return i16();
-               else
-               if(m<=65536)
-                       return i16()%m;
-               else
-                       return i32()%m;
-       }
-};
-
 #define GUID_RNG quick_rng
 //#define GUID_RNG subtractive_rng
 
@@ -146,10 +104,10 @@ static void _get_rand_long_long(uint64_t &x)
 {
        //subtractive_rng _c(clock());
        unsigned short* data(reinterpret_cast<unsigned short *>(&x));
-       data[0]=_a(65536);      
-       data[1]=_a(65536);      
-       data[2]=_a(65536);      
-       data[3]=_a(65536);      
+       data[0]=_a(65536);
+       data[1]=_a(65536);
+       data[2]=_a(65536);
+       data[3]=_a(65536);
 }
 
 #else
@@ -160,7 +118,7 @@ static void _get_rand_long_long(uint64_t &x)
 static void get_rand_long_long(uint64_t &x)
 {
        _GUID* guid(reinterpret_cast<_GUID*>(&x));
-       CoCreateGuid(guid);     
+       CoCreateGuid(guid);
 }
 
 #else
@@ -195,7 +153,7 @@ synfig::GUID::make_unique()
 
 synfig::GUID
 synfig::GUID::hasher(const String& str)
-{      
+{
 #ifdef HASH_MAP_H
        hash<const char*> string_hash_;
        const unsigned int seed(
@@ -211,7 +169,7 @@ synfig::GUID::hasher(const String& str)
                seed=(seed>>(32-(i%24)))^(seed<<(i%24))
        }
 #endif
-       
+
        GUID_RNG random(seed);
        GUID ret(0);
        ret.data.u_32.a=random(~(unsigned int)0);