mardi 25 juillet 2017

Random number generator code fix (alternative for srand48/drand48)

Let me start by saying that I know near nothing about C and C++. That being said, I need to wrap some older code so am trying to struggle through it. Now, when trying to run a test, I get the error

Unresolvedexternal symbol srand45...

And the same for drand48.

The code I'm using starts as follows:

#include <stdio.h>
#include "arrays.h"
#include "poker.h"

void srand48();
double drand48();

And continues to use srand48 and drand48 in these snippets of code:

// Seed the random number generator.
srand48(getpid());

And for drand48:

//
//  This routine takes a deck and randomly mixes up
//  the order of the cards.
//
void
shuffle_deck(int *deck)
{
    int i, n, temp[52];

    for (i = 0; i < 52; i++)
        temp[i] = deck[i];

    for (i = 0; i < 52; i++)
    {
        do {
            n = (int)(51.9999999 * drand48());
        } while (temp[n] == 0);
        deck[i] = temp[n];
        temp[n] = 0;
    }
}

The full code can be found here: http://ift.tt/2v3QkN0

But I can't think of a way to fix this issue, even though it seems very minor. That said, speed is absolutely essential, as the code will be run several millions of times. I'm using visualstudio on a x64 machine.




Aucun commentaire:

Enregistrer un commentaire