Changeset 896 for cpp/frams/genetics


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

Location:
cpp/frams/genetics
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f4/f4_general.cpp

    r853 r896  
    12101210        int n = count();
    12111211        // pick a random node, between 0 and n-1
    1212         return ordNode(randomN(n));
     1212        return ordNode(rndUint(n));
    12131213}
    12141214
     
    13551355{
    13561356        int i, j, res, t;
    1357         char tc1, tc2, tc3; // tc3 is only to ensure that in the end  of neuron parameter definition
     1357        char tc1, tc2, tc3; // tc3 is only to ensure that neuron parameter definition is completed
    13581358        int relfrom;
    13591359        double w;
  • cpp/frams/genetics/f4/f4_oper.cpp

    r779 r896  
    158158                        // "X>" or "N>"
    159159                        f4_node *n5 = NULL;
    160                         double pr = rnd01;
     160                        double pr = rndDouble(1);
    161161                        pr -= 0.5;
    162162                        if (pr < 0) n5 = new f4_node('X', n2, n2->pos);
     
    204204                        n1->parent = n2;
    205205                        // now with 50% chance swap children
    206                         if (randomN(2) == 0)
     206                        if (rndUint(2) == 0)
    207207                        {
    208208                                n3 = n2->child;
     
    275275                        // choose a simple node from ADD_SIMPLE_CODES
    276276                        n1->parent->removeChild(n1);
    277                         //f4_node *n2 = new f4_node(ADD_SIMPLE_CODES[randomN(strlen(ADD_SIMPLE_CODES))], n1->parent, n1->parent->pos);
     277                        //f4_node *n2 = new f4_node(ADD_SIMPLE_CODES[rndUint(strlen(ADD_SIMPLE_CODES))], n1->parent, n1->parent->pos);
    278278                        int modifierid = GenoOperators::getRandomChar(all_modifiers, excluded_modifiers.c_str());
    279279                        f4_node *n2 = new f4_node(all_modifiers[modifierid], n1->parent, n1->parent->pos);
     
    333333                                n2->removeChild(n1);
    334334                                // n1 has two children. pick one randomly 50-50, destroy other
    335                                 if (randomN(2) == 0)
     335                                if (rndUint(2) == 0)
    336336                                {
    337337                                        n1->child->parent = n2;
     
    429429
    430430        // 35% chance one of *GTS
    431         prob1 = rnd01;
     431        prob1 = rndDouble(1);
    432432        prob1 -= 0.35f;
    433433        if (prob1 < 0)
     
    468468        case 0: // change type
    469469                // 80% for link, 20% for random sensor
    470                 if (rnd01 < 0.2f)
     470                if (rndDouble(1) < 0.2f)
    471471                {
    472472                        cl = GenoOperators::getRandomNeuroClassWithOutputAndNoInputs();
     
    497497void Geno_f4::nparNodeMakeRandom(f4_node *nn) const
    498498{
    499         int sign = (int)(2.0f * rnd01);
    500         int param = (int)(3.0f * rnd01);
     499        int sign = (int)rndDouble(2);
     500        int param = (int)rndDouble(3);
    501501        if (param > 2) param = 2;
    502502        nn->l1 = sign;
     
    512512        // change count
    513513        count = nn->i1;
    514         prob1 = rnd01;
     514        prob1 = rndDouble(1);
    515515        if (prob1 < 0.5f) count++;
    516516        else count--;
     
    699699        // decide amounts of crossover, 0.25-0.75
    700700        // adam: seems 0.1-0.9 -- MacKo
    701         chg1 = 0.1f + 0.8f*rnd01;
    702         chg2 = 0.1f + 0.8f*rnd01;
     701        chg1 = 0.1 + rndDouble(0.8);
     702        chg2 = 0.1 + rndDouble(0.8);
    703703
    704704        copy1 = root1.duplicate();
  • cpp/frams/genetics/f9/f9_oper.cpp

    r779 r896  
    55#include "f9_oper.h"
    66#include "f9_conv.h"
    7 #include <common/nonstd.h> //randomN, rnd01
     7#include <common/nonstd.h> //rndUint, rnd01
    88
    99
     
    5555        for (int i = 0; i < len; i++)
    5656        {
    57                 if (rnd01 < mut_prob) //normalize prob with the length of the genotype
     57                if (rndDouble(1) < mut_prob) //normalize prob with the length of the genotype
    5858                {
    5959                        char oldgene = gene[i];
    60                         gene[i] = turtle_commands_f9[randomN(symbols)];
     60                        gene[i] = turtle_commands_f9[rndUint(symbols)];
    6161                        if (gene[i] != oldgene) changes++;
    6262                }
    6363        }
    6464
    65         if (rnd01 < mut_prob) //add or delete a random char
     65        if (rndDouble(1) < mut_prob) //add or delete a random char
    6666        {
    6767                SString newgeno(gene);
    68                 if (randomN(2) == 0) //add
     68                if (rndUint(2) == 0) //add
    6969                {
    7070                        int symbols = strlen(turtle_commands_f9);
    71                         int p = randomN(len + 1);  //random location
     71                        int p = rndUint(len + 1);  //random location
    7272                        //printf("before add: %s\n",(const char*)newgeno);
    73                         newgeno = newgeno.substr(0, p) + SString(turtle_commands_f9 + randomN(symbols), 1) + newgeno.substr(p);
     73                        newgeno = newgeno.substr(0, p) + SString(turtle_commands_f9 + rndUint(symbols), 1) + newgeno.substr(p);
    7474                        //printf("after add: %s\n",(const char*)newgeno);
    7575                        changes++;
     
    7777                else if (len > 1) //delete
    7878                {
    79                         int p = randomN(len);  //random location
     79                        int p = rndUint(len);  //random location
    8080                        //printf("before delete: %s\n",(const char*)newgeno);
    8181                        newgeno = newgeno.substr(0, p) + newgeno.substr(p + 1);
     
    9595{
    9696        int len1 = strlen(g1), len2 = strlen(g2);
    97         int p1 = randomN(len1);  //random cut point for first genotype
    98         int p2 = randomN(len2);  //random cut point for second genotype
     97        int p1 = rndUint(len1);  //random cut point for first genotype
     98        int p2 = rndUint(len2);  //random cut point for second genotype
    9999        char *child1 = (char*)malloc(p1 + len2 - p2 + 1);
    100100        char *child2 = (char*)malloc(p2 + len1 - p1 + 1);
  • cpp/frams/genetics/fB/fB_oper.cpp

    r853 r896  
    246246        {
    247247                std::list<SString> tokenized = tokenizeSequence(line);
    248                 int rndid = randomN(tokenized.size()); // select random letter from genotype
     248                int rndid = rndUint(tokenized.size()); // select random letter from genotype
    249249                // increment/decrement character - when overflow happens, this method
    250250                // uses reflect method
     
    254254                if ((*it).len() == 1)
    255255                {
    256                         if (randomN(2) == 0)
     256                        if (rndUint(2) == 0)
    257257                        {
    258258                                if ((*it)[0] == 'a') (*it).directWrite()[0] = 'b';
     
    285285                std::list<SString> tokenized = tokenizeSequence(line);
    286286                std::list<SString>::iterator it = tokenized.begin();
    287                 int rndid = randomN(tokenized.size()); // select random insertion point
     287                int rndid = rndUint(tokenized.size()); // select random insertion point
    288288                std::advance(it, rndid);
    289289                NeuroClass *cls = getRandomNeuroClass();
     
    306306                chg = 1.0 / line.len();
    307307                std::list<SString> tokenized = tokenizeSequence(line);
    308                 int rndid = randomN(tokenized.size()); // select random insertion point
     308                int rndid = rndUint(tokenized.size()); // select random insertion point
    309309                std::list<SString>::iterator it = tokenized.begin();
    310310                std::advance(it, rndid);
    311311                SString letter = "a";
    312                 letter.directWrite()[0] = 'a' + randomN(26);
     312                letter.directWrite()[0] = 'a' + rndUint(26);
    313313                tokenized.insert(it, letter);
    314314                line = detokenizeSequence(&tokenized);
     
    320320                std::list<SString> tokenized = tokenizeSequence(line);
    321321                std::list<SString>::iterator it = tokenized.begin();
    322                 int rndid = randomN(tokenized.size()); // select random deletion point
     322                int rndid = rndUint(tokenized.size()); // select random deletion point
    323323                std::advance(it, rndid);
    324324                tokenized.erase(it);
     
    328328        case FB_DUPLICATION:
    329329        {
    330                 int rndgene = randomN(fB_GenoHelpers::geneCount(line));
     330                int rndgene = rndUint(fB_GenoHelpers::geneCount(line));
    331331                int start, end;
    332332                SString gene = fB_GenoHelpers::getGene(rndgene, line, start, end);
     
    342342                for (int i = 0; i < 4; i++)
    343343                {
    344                         cuts[i] = randomN(tokenized.size());
     344                        cuts[i] = rndUint(tokenized.size());
    345345                }
    346346                std::sort(cuts.begin(), cuts.end());
     
    407407        {
    408408                // get random gene from first parent
    409                 int choice = randomN(fB_GenoHelpers::geneCount(parent1));
     409                int choice = rndUint(fB_GenoHelpers::geneCount(parent1));
    410410                int start, end;
    411411                SString gene = fB_GenoHelpers::getGene(choice, parent1, start, end);
     
    414414                chg2 = (float)parent2.len() / (float)child2.len();
    415415                // do the same for second parent
    416                 choice = randomN(fB_GenoHelpers::geneCount(parent2));
     416                choice = rndUint(fB_GenoHelpers::geneCount(parent2));
    417417                gene = fB_GenoHelpers::getGene(choice, parent2, start, end);
    418418                child1 = gene + parent1;
     
    428428        //                      int start, end;
    429429        //                      SString gene = fB_GenoHelpers::getGene(i, parent1, start, end);
    430         //                      if (randomN(2) == 0)
     430        //                      if (rndUint(2) == 0)
    431431        //                      {
    432432        //                              child1 += gene;
     
    445445        //                      int start, end;
    446446        //                      SString gene = fB_GenoHelpers::getGene(i, parent2, start, end);
    447         //                      if (randomN(2) == 0)
     447        //                      if (rndUint(2) == 0)
    448448        //                      {
    449449        //                              child1 += gene;
     
    474474                                i < fB_GenoHelpers::geneCountNoNested(parent2))
    475475                        {
    476                                 if (randomN(2) == 0)
     476                                if (rndUint(2) == 0)
    477477                                {
    478478                                        to1 = fB_GenoHelpers::getNonNestedGene(i, parent1, start, end);
     
    489489                        else if (i < fB_GenoHelpers::geneCountNoNested(parent1))
    490490                        {
    491                                 if (randomN(2) == 0)
     491                                if (rndUint(2) == 0)
    492492                                {
    493493                                        to1 = fB_GenoHelpers::getNonNestedGene(i, parent1, start, end);
     
    501501                        else // if (i < fB_GenoHelpers::geneCountNoNested(parent2))
    502502                        {
    503                                 if (randomN(2) == 0)
     503                                if (rndUint(2) == 0)
    504504                                {
    505505                                        to1 = fB_GenoHelpers::getNonNestedGene(i, parent2, start, end);
  • cpp/frams/genetics/fF/fF_oper.cpp

    r779 r896  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
    55#include "fF_oper.h"
    66#include "fF_genotype.h"
    7 #include <common/nonstd.h> //randomN, rnd01
     7#include <common/nonstd.h> //rndUint, rnd01
    88
    99
     
    4949        par.load(gene);
    5050        static const int propsToMutate[] = fF_PROPS_TO_MUTATE;
    51         int which = randomN(ARRAY_LENGTH(propsToMutate));
     51        int which = rndUint(ARRAY_LENGTH(propsToMutate));
    5252        bool mutated_ok = GenoOperators::mutatePropertyNaive(par.param, propsToMutate[which]);
    5353        if (mutated_ok)
  • cpp/frams/genetics/fH/fH_oper.cpp

    r803 r896  
    107107        for (unsigned int i = 0; i < parent1->sticks.size(); i++)
    108108        {
    109                 if (randomN(2) == 0)
     109                if (rndUint(2) == 0)
    110110                {
    111111                        child1->sticks.push_back(parent1->sticks[i]);
     
    120120        for (unsigned int i = 0; i < parent2->sticks.size(); i++)
    121121        {
    122                 if (randomN(2) == 0)
     122                if (rndUint(2) == 0)
    123123                {
    124124                        child1->sticks.push_back(parent2->sticks[i]);
     
    140140        for (unsigned int i = 0; i < parent1->neurons.size(); i++)
    141141        {
    142                 if ((randomN(2) == 0 || skip2) && !skip1)
     142                if ((rndUint(2) == 0 || skip2) && !skip1)
    143143                {
    144144                        child1->neurons.push_back(parent1->neurons[i]);
     
    153153        for (unsigned int i = 0; i < parent2->neurons.size(); i++)
    154154        {
    155                 if ((randomN(2) == 0 || skip2) && !skip1)
     155                if ((rndUint(2) == 0 || skip2) && !skip1)
    156156                {
    157157                        child1->neurons.push_back(parent2->neurons[i]);
     
    166166        for (unsigned int i = 0; i < parent1->connections.size(); i++)
    167167        {
    168                 if ((randomN(2) == 0 || skip2) && !skip1)
     168                if ((rndUint(2) == 0 || skip2) && !skip1)
    169169                {
    170170                        child1->connections.push_back(parent1->connections[i]);
     
    179179        for (unsigned int i = 0; i < parent2->connections.size(); i++)
    180180        {
    181                 if ((randomN(2) == 0 || skip2) && !skip1)
     181                if ((rndUint(2) == 0 || skip2) && !skip1)
    182182                {
    183183                        child1->connections.push_back(parent2->connections[i]);
     
    338338        if (changedimensions)
    339339        {
    340                 int i = randomN(2 * dimensions);
     340                int i = rndUint(2 * dimensions);
    341341                changeDoubleProperty(i, par, handle->type);
    342342        }
     
    344344        if (changeproperties)
    345345        {
    346                 int i = 2 * dimensions + randomN(par.getPropCount() - 2 * dimensions);
     346                int i = 2 * dimensions + rndUint(par.getPropCount() - 2 * dimensions);
    347347                changeDoubleProperty(i, par, handle->type);
    348348        }
     
    360360        for (int i = 0; i < dimensions; i++)
    361361        {
    362                 par.setDouble(i, min + rnd0N(max - min));
    363                 par.setDouble(i + dimensions, min + rnd0N(max - min));
     362                par.setDouble(i, min + rndDouble(max - min));
     363                par.setDouble(i + dimensions, min + rndDouble(max - min));
    364364        }
    365365        handle->loadProperties(par);
    366366        if (handle->type != fHBodyType::NEURON)
    367367        {
    368                 int i = 2 * dimensions + randomN(par.getPropCount() - 2 * dimensions);
     368                int i = 2 * dimensions + rndUint(par.getPropCount() - 2 * dimensions);
    369369                changeDoubleProperty(i, par, handle->type);
    370370        }
     
    406406                allhandlescount += creature->sticks.size();
    407407        }
    408         unsigned int toselect = randomN(allhandlescount);
     408        unsigned int toselect = rndUint(allhandlescount);
    409409        if (toselect < creature->connections.size())
    410410        {
     
    436436        if (par.getPropCount() > 0)
    437437        {
    438                 int i = randomN(par.getPropCount());
     438                int i = rndUint(par.getPropCount());
    439439                if (*par.type(i) == 'f')
    440440                {
  • cpp/frams/genetics/fL/fL_matheval.cpp

    r821 r896  
    613613void MathEvaluation::mutateValueOrVariable(MathEvaluation::Number *&currval, bool usetime)
    614614{
    615         if (randomN(2) == 0 && varcount > 0) // use variable
     615        if (rndUint(2) == 0 && varcount > 0) // use variable
    616616        {
    617617                if (currval && currval->type == TokenType::NUMBER)
     
    619619                        delete currval;
    620620                }
    621                 int var = randomN(varcount + (usetime ? 1 : 0));
     621                int var = rndUint(varcount + (usetime ? 1 : 0));
    622622                if (varcount == var) // time is used
    623623                {
     
    633633                if (!currval || currval->type == TokenType::VARIABLE)
    634634                {
    635                         currval = new Number(rnd01);
     635                        currval = new Number(rndDouble(1));
    636636                }
    637637                else
    638638                {
    639                         currval->value = rnd01;
     639                        currval->value = rndDouble(1);
    640640                }
    641641        }
     
    654654                count = operatorstrings.size() - arithmeticoperatorscount;
    655655        }
    656         randop += randomN(count);
     656        randop += rndUint(count);
    657657        return operators[operatorstrings[randop]];
    658658}
     
    663663        {
    664664                int currsize = postfixlist.size();
    665                 int varid = randomN(varcount);
     665                int varid = rndUint(varcount);
    666666                postfixlist.push_back(vars[varid]);
    667                 if (randomN(2) == 0 && varcount > 1)
    668                 {
    669                         int varid2 = randomN(varcount - 1);
     667                if (rndUint(2) == 0 && varcount > 1)
     668                {
     669                        int varid2 = rndUint(varcount - 1);
    670670                        if (varid2 >= varid) varid2++;
    671671                        postfixlist.push_back(vars[varid2]);
     
    673673                else
    674674                {
    675                         Number *num = new Number(rnd01);
     675                        Number *num = new Number(rndDouble(1));
    676676                        postfixlist.push_back(num);
    677677                }
    678                 int opid = arithmeticoperatorscount + randomN(comparisonoperatorscount);
     678                int opid = arithmeticoperatorscount + rndUint(comparisonoperatorscount);
    679679                postfixlist.push_back(operators[operatorstrings[opid]]);
    680680                if (currsize > 0)
     
    689689        if (postfixlist.size() == 0)
    690690        {
    691                 Number *val = new Number(rnd01);
     691                Number *val = new Number(rndDouble(1));
    692692                postfixlist.push_back(val);
    693693                return -1;
    694694        }
    695         int method = randomN(postfixlist.size() < MAX_MUT_FORMULA_SIZE ? MATH_MUT_COUNT : MATH_MUT_COUNT - 1);
     695        int method = rndUint(postfixlist.size() < MAX_MUT_FORMULA_SIZE ? MATH_MUT_COUNT : MATH_MUT_COUNT - 1);
    696696        switch (method)
    697697        {
     
    704704                std::list<Token *>::iterator it = postfixlist.begin();
    705705                // insertion can be applied from 1st occurrence
    706                 int insertlocation = 1 + randomN(postfixlist.size() - 1);
     706                int insertlocation = 1 + rndUint(postfixlist.size() - 1);
    707707                std::advance(it, insertlocation);
    708708                Operator *rndop;
     
    732732                        id++;
    733733                }
    734                 int randid = randomN(numbersineval.size());
     734                int randid = rndUint(numbersineval.size());
    735735                Number *numptr = (Number *)(*numbersineval[randid]);
    736736                mutateValueOrVariable(numptr, usetime);
     
    750750                if (ops.size() > 0)
    751751                {
    752                         int randid = randomN(ops.size());
     752                        int randid = rndUint(ops.size());
    753753                        Operator *rndop;
    754754                        if (randid == (int)ops.size() - 1)
     
    783783                if (firstofpairs.size() > 0)
    784784                {
    785                         int rndid = randomN(firstofpairs.size());
     785                        int rndid = rndUint(firstofpairs.size());
    786786                        if ((*firstofpairs[rndid])->type == TokenType::NUMBER)
    787787                        {
  • cpp/frams/genetics/fL/fL_oper.cpp

    r853 r896  
    133133                if (newword->name.startsWith("rot"))
    134134                {
    135                         double rot = 2 * rnd01;
     135                        double rot = rndDouble(2);
    136136                        MathEvaluation *eval = new MathEvaluation(0);
    137137                        eval->convertString(SString::valueOf(rot).c_str());
     
    149149                {
    150150                        MathEvaluation *eval = new MathEvaluation(0);
    151                         eval->convertString(SString::valueOf(2 * rnd01 - 1).c_str());
     151                        eval->convertString(SString::valueOf(rndDouble(2) - 1).c_str());
    152152                        newword->parevals[0] = eval;
    153153                }
     
    171171        else
    172172        {
    173                 int rid = randomN(creature->rules.size());
     173                int rid = rndUint(creature->rules.size());
    174174                list = &creature->rules[rid]->objsucc;
    175175                numparams = creature->rules[rid]->objpred->npar;
     
    183183        if (method == FL_ADD_OTHER && creature->builtincount < (int)creature->words.size())
    184184        {
    185                 return creature->words[creature->wordnames[creature->builtincount + randomN((int)creature->words.size() - creature->builtincount)]];
     185                return creature->words[creature->wordnames[creature->builtincount + rndUint((int)creature->words.size() - creature->builtincount)]];
    186186        }
    187187        else
     
    209209                case FL_ADD_ROT:
    210210                {
    211                         int rottype = randomN(3);
     211                        int rottype = rndUint(3);
    212212                        switch (rottype)
    213213                        {
     
    287287                case FL_CHG_ITER:
    288288                {
    289                         if (randomN(2) == 0)
     289                        if (rndUint(2) == 0)
    290290                        {
    291291                                creature->time = creature->time + iterchangestep <= ExtValue::getDouble(FL_MAXITER) ?
     
    303303                        if (creature->rules.size() > 0)
    304304                        {
    305                                 int ruleid = randomN(creature->rules.size());
     305                                int ruleid = rndUint(creature->rules.size());
    306306                                if (!creature->rules[ruleid]->condeval)
    307307                                {
     
    340340                        if (wordswithnorules.size() > 0)
    341341                        {
    342                                 int predid = randomN(wordswithnorules.size());
     342                                int predid = rndUint(wordswithnorules.size());
    343343                                fL_Rule *newrule = new fL_Rule(0,0);
    344344                                fL_Word *pred = new fL_Word();
     
    352352                        else if (creature->rules.size() > 0)
    353353                        {
    354                                 int ruleid = randomN(creature->rules.size());
     354                                int ruleid = rndUint(creature->rules.size());
    355355                                fL_Rule *newrule = new fL_Rule(0, 0);
    356356                                fL_Word *pred = new fL_Word();
     
    392392                        if (creature->countDefinedWords() <= maxdefinedwords)
    393393                        {
    394                                 int npar = randomN(ExtValue::getInt(FL_MAXPARAMS, false));
     394                                int npar = rndUint(ExtValue::getInt(FL_MAXPARAMS, false));
    395395                                for (int i = 0; i < maxdefinedwords; i++)
    396396                                {
     
    421421                                if (list->size() > 1)
    422422                                {
    423                                         int rndid = randomN(list->size() - 1);
     423                                        int rndid = rndUint(list->size() - 1);
    424424                                        int j = 0;
    425425                                        std::list<fL_Word *>::iterator it = list->begin();
     
    455455                        else
    456456                        {
    457                                 int rndid = randomN(list->size());
     457                                int rndid = rndUint(list->size());
    458458                                std::list<fL_Word *>::iterator it = list->begin();
    459459                                std::advance(it, rndid);
     
    482482                        int tmp = 0;
    483483                        std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp);
    484                         int rndid = randomN(list->size());
     484                        int rndid = rndUint(list->size());
    485485                        std::list<fL_Word *>::iterator it = list->begin();
    486486                        std::advance(it, rndid);
     
    512512                                fL_Branch *start = new fL_Branch(fL_Branch::BranchType::OPEN, 0, 0);
    513513                                list->insert(it, start);
    514                                 int rottype = randomN(2);
     514                                int rottype = rndUint(2);
    515515                                switch (rottype)
    516516                                {
     
    531531                        int tmp = 0;
    532532                        std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp);
    533                         int rndid = randomN(list->size());
     533                        int rndid = rndUint(list->size());
    534534                        std::list<fL_Word *>::iterator selectedword = list->begin();
    535535                        std::advance(selectedword, rndid);
     
    545545                                int numpars = 0;
    546546                                std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp);
    547                                 int rndid = randomN(list->size());
     547                                int rndid = rndUint(list->size());
    548548                                std::list<fL_Word *>::iterator it = list->begin();
    549549                                std::advance(it, rndid);
     
    577577                                        if (available.size() > 0)
    578578                                        {
    579                                                 int newnameid = randomN(available.size());
     579                                                int newnameid = rndUint(available.size());
    580580                                                (*selectedword)->name = available[newnameid]->name;
    581581                                        }
     
    593593                                if ((*selectedword)->npar > 0)
    594594                                {
    595                                         int randeval = randomN((*selectedword)->npar);
     595                                        int randeval = rndUint((*selectedword)->npar);
    596596                                        Param par((*selectedword)->tab, (*selectedword)->data);
    597597                                        if ((*selectedword)->builtin && (*selectedword)->name == "N"
     
    614614                                                        if (w->npar > 0)
    615615                                                        {
    616                                                                 int rndattr = randomN(w->npar);
     616                                                                int rndattr = rndUint(w->npar);
    617617                                                                if (!w->parevals[rndattr])
    618618                                                                {
     
    638638                                                                if (w->npar > 0)
    639639                                                                {
    640                                                                         int rndattr = randomN(w->npar);
     640                                                                        int rndattr = rndUint(w->npar);
    641641                                                                        for (int i = 0; i < w->npar; i++)
    642642                                                                        {
     
    752752                for (int i = 0; i < numselrules; i++)
    753753                {
    754                         int rulid = randomN(from->rules.size());
     754                        int rulid = rndUint(from->rules.size());
    755755                        fL_Rule *rul = from->rules[rulid];
    756756                        fL_Rule *newrule = new fL_Rule(0, 0);
     
    841841        creature2template->parseGenotype(g2);
    842842
    843         int numselrules = 1 + randomN(XOVER_MAX_MIGRATED_RULES);
     843        int numselrules = 1 + rndUint(XOVER_MAX_MIGRATED_RULES);
    844844        numselrules = numselrules < (int)creature1->rules.size() ? numselrules : (int)creature1->rules.size();
    845845
    846846        migrateRandomRules(creature1template, creature2, numselrules);
    847847
    848         numselrules = 1 + randomN(XOVER_MAX_MIGRATED_RULES);
     848        numselrules = 1 + rndUint(XOVER_MAX_MIGRATED_RULES);
    849849        numselrules = numselrules < (int)creature1->rules.size() ? numselrules : (int)creature1->rules.size();
    850850
  • cpp/frams/genetics/fT/fTest_oper.cpp

    r779 r896  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    8888        int changes = 0, len = strlen(geno);
    8989        for (int i = 0; i < len; i++)
    90                 if (rnd01 < prob) //normalize prob with length of genotype
     90                if (rndDouble(1) < prob) //normalize prob with length of genotype
    9191                {
    92                         geno[i] = a[randomN(4)];
     92                        geno[i] = a[rndUint(4)];
    9393                        changes++;
    9494                }
     
    101101{
    102102        int len1 = strlen(g1), len2 = strlen(g2);
    103         int p1 = randomN(len1);  //random cut point for first genotype
    104         int p2 = randomN(len2);  //random cut point for second genotype
     103        int p1 = rndUint(len1);  //random cut point for first genotype
     104        int p2 = rndUint(len2);  //random cut point for second genotype
    105105        char *child1 = (char*)malloc(p1 + len2 - p2 + 1);
    106106        char *child2 = (char*)malloc(p2 + len1 - p1 + 1);
  • cpp/frams/genetics/fn/fn_oper.cpp

    r809 r896  
    55#include "fn_oper.h"
    66#include "fn_conv.h"
    7 #include <common/nonstd.h> //randomN, rnd01
     7#include <common/nonstd.h> //rndUint, rnd01
    88
    99
     
    8080        if (mut_single_var) //mutate only one, randomly selected variable
    8181        {
    82                 int which = randomN(values.size());
     82                int which = rndUint(values.size());
    8383                values[which] = GenoOperators::mutateCreep('f', values[which], bound_low[which], bound_high[which], stddev[which], false);
    8484                chg = 1.0f / values.size();
     
    103103        //xover_proportion = 0.1; //testing...
    104104
    105         double proportion = xover_proportion_random ? 0.5 + rnd0N(0.5) : xover_proportion;
     105        double proportion = xover_proportion_random ? 0.5 + rndDouble(0.5) : xover_proportion;
    106106
    107107        chg1 = proportion;
  • cpp/frams/genetics/genman.cpp

    r841 r896  
    362362                {
    363363                        char *gn;
    364                         if (g1n[0] && g2n[0]) if (randomN(2) == 0) g1n[0] = 0; else g2n[0] = 0; //both provided? we want only one
     364                        if (g1n[0] && g2n[0]) if (rndUint(2) == 0) g1n[0] = 0; else g2n[0] = 0; //both provided? we want only one
    365365                        if (g1n[0]) { gn = g1n; chg = chg1; }
    366366                        else { gn = g2n; chg = chg2; }
  • 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.