Użytkownik:Gal/Brudnopis: Różnice pomiędzy wersjami

brak opisu edycji
Nie podano opisu zmian
Nie podano opisu zmian
Linia 1: Linia 1:
== Mieszacz genów  ==
Pl: mieszacz genów
En: Geno-randomizer
Nazwa na cześć maszyny Mesogoga
<pre>
function genoRandomizer(a) {
const pairs = []
for (let i = 0; i < a.length; i+=2 ) {
console.log(i)
pairs.push([a[i],a[i+1]])
}
    const children = []
for (let i of pairs) {
   
for (let j = 0; j < 4; j++) {
let a = i[0][Math.round(Math.random())]
let b = i[1][Math.round(Math.random())]
children.push([a,b])
}
}
return children
}
</pre>
Łączymy z czymś co miesza tablice np. tu https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array znalazłem
<pre>
function shuffle(array) {
  let currentIndex = array.length,  randomIndex;
  // While there remain elements to shuffle.
  while (currentIndex != 0) {
    // Pick a remaining element.
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex--;
    // And swap it with the current element.
    [array[currentIndex], array[randomIndex]] = [
      array[randomIndex], array[currentIndex]];
  }
  return array;
}
</pre>
I mamy <pre>
genoRandomizer(shuffle(genoRandomizer(shuffle(genoRandomizer([['x','Y'],['X','X']])))))
<pre/>
== Python kod ==
== Python kod ==


338

edycji