Changeset 388


Ignore:
Timestamp:
05/24/15 21:01:18 (9 years ago)
Author:
Maciej Komosinski
Message:

A local PRBS-7 implementation so that this file does not depend on external random number generators

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/model/similarity/SVD/lapack.cpp

    r368 r388  
    4747 * AutoBuffer from https://github.com/Itseez/opencv/blob/master/modules/core/include/opencv2/core/utility.hpp
    4848 * VBLAS, JacobiSVDImpl_ from https://github.com/Itseez/opencv/blob/master/modules/core/src/lapack.cpp
    49  * changes:
    50  * - "RNG rng(0x12345678)" replaced with "srand(time(NULL))"
    51  * - "rng.next()" replaced with "rand()"
    52  * MK, 04.2015:
    53  * - commented out "srand(time(NULL))" - this line would affect everything else that uses the standard global r.n.g., and would introduce uncontrolled indeterminism
     49 * changes MK, May 2015:
     50 * - "RNG rng(0x12345678)" and "rng.next()" replaced with a local PRBS-7 implementation so that this file does not depend on external random number generators.
    5451 */
    5552#include <cstdlib>
     
    5855#include <limits>
    5956#include <cfloat>
    60 #include <assert.h>
     57//#include <assert.h>
     58#include <math.h> //hypot(), embarcadero
     59#include <stdint.h> //uint8_t
    6160#include "lapack.h"
    62 #include <stdlib.h> //rand(), embarcadero
    63 #include <math.h> //hypot(), embarcadero
    64 
    65 typedef unsigned char uchar;
     61
    6662
    6763#if defined _M_IX86 && defined _MSC_VER && _MSC_VER < 1700
     
    376372        return;
    377373
    378     //srand(time(NULL));
    379     for (i = 0; i < n1; i++)
     374        uint8_t rndstate = 0x02; //PRBS-7 from http://en.wikipedia.org/wiki/Pseudorandom_binary_sequence
     375        for (i = 0; i < n1; i++)
    380376    {
    381377        sd = i < n ? W[i] : 0;
     
    389385            for (k = 0; k < m; k++)
    390386            {
    391                 _Tp val = (rand() & 256) != 0 ? val0 : -val0;
     387                                int rndbit = (((rndstate >> 6) ^ (rndstate >> 5)) & 1);
     388                                rndstate = ((rndstate << 1) | rndbit) & 0x7f;
     389                                _Tp val = rndbit == 0 ? val0 : -val0;
    392390                At[i * astep + k] = val;
    393391            }
Note: See TracChangeset for help on using the changeset viewer.