/* ------------------------------------------------------------------------- */ int selection(deme *subpop) { int i, my_rank; double current_sum = 0.0; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); long double rand = mt_rand_real(subpop->fit_tot, my_rank); for (i = 0; i < subpop->pop_size && current_sum <= rand; i++) current_sum += subpop->old_pop[i]->fitness; return i-1; }
static mrb_value mrb_random_mt_rand(mrb_state *mrb, mt_state *t, mrb_value max) { mrb_value value; if (mrb_fixnum(max) == 0) { value = mrb_float_value(mrb, mt_rand_real(t)); } else { value = mrb_fixnum_value(mt_rand(t) % mrb_fixnum(max)); } return value; }