Ignore:
Timestamp:
11/30/19 01:30:22 (4 years ago)
Author:
Maciej Komosinski
Message:

Replaced #defined macros for popular random-related operations with functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/genooperators.cpp

    r801 r896  
    3838        int i;
    3939        for (i = 0; i < count; i++) sum += probtab[i];
    40         double sel = rnd01*sum;
     40        double sel = rndDouble(sum);
    4141        for (sum = 0, i = 0; i < count; i++) { sum += probtab[i]; if (sel < sum) return i; }
    4242        return -1;
     
    8181                neucls = n->getClass() == NULL ? 0 : n->getClass()->getProperties().getPropCount();
    8282        if (neuext + neucls == 0) return -1; //no properties in this neuron
    83         int index = randomN(neuext + neucls);
     83        int index = rndUint(neuext + neucls);
    8484        if (index >= neuext) index = index - neuext + 100;
    8585        return index;
     
    142142        {
    143143                result = int(result + 0.5);
    144                 if (result == current) result += randomN(2) * 2 - 1; //force some change
     144                if (result == current) result += rndUint(2) * 2 - 1; //force some change
    145145        }
    146146        else
     
    238238                if (Neuro::getClass(i)->genactive)
    239239                        active.push_back(Neuro::getClass(i));
    240         if (active.size() == 0) return NULL; else return active[randomN(active.size())];
     240        if (active.size() == 0) return NULL; else return active[rndUint(active.size())];
    241241}
    242242
     
    247247                if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredOutput() != 0)
    248248                        active.push_back(Neuro::getClass(i));
    249         if (active.size() == 0) return NULL; else return active[randomN(active.size())];
     249        if (active.size() == 0) return NULL; else return active[rndUint(active.size())];
    250250}
    251251
     
    256256                if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredInputs() != 0)
    257257                        active.push_back(Neuro::getClass(i));
    258         if (active.size() == 0) return NULL; else return active[randomN(active.size())];
     258        if (active.size() == 0) return NULL; else return active[rndUint(active.size())];
    259259}
    260260
     
    265265                if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredOutput() != 0 && Neuro::getClass(i)->getPreferredInputs() == 0)
    266266                        active.push_back(Neuro::getClass(i));
    267         if (active.size() == 0) return NULL; else return active[randomN(active.size())];
     267        if (active.size() == 0) return NULL; else return active[rndUint(active.size())];
    268268}
    269269
     
    274274                if (NClist[i]->getPreferredOutput() != 0) //this NeuroClass provides output
    275275                        allowed.push_back(i);
    276         if (allowed.size() == 0) return -1; else return allowed[randomN(allowed.size())];
     276        if (allowed.size() == 0) return -1; else return allowed[rndUint(allowed.size())];
    277277}
    278278
     
    283283                if (NClist[i]->getPreferredInputs() != 0) //this NeuroClass wants one input connection or more                 
    284284                        allowed.push_back(i);
    285         if (allowed.size() == 0) return -1; else return allowed[randomN(allowed.size())];
     285        if (allowed.size() == 0) return -1; else return allowed[rndUint(allowed.size())];
    286286}
    287287
     
    291291        for (size_t i = 0; i < strlen(choices); i++) if (!strchrn0(excluded, choices[i])) allowed_count++;
    292292        if (allowed_count == 0) return -1; //no char is allowed
    293         int rnd_index = randomN(allowed_count) + 1;
     293        int rnd_index = rndUint(allowed_count) + 1;
    294294        allowed_count = 0;
    295295        for (size_t i = 0; i < strlen(choices); i++)
Note: See TracChangeset for help on using the changeset viewer.