Skip to content

Commit 09d050e

Browse files
authored
Merge pull request #370 from vplentinax/generators
Generators
2 parents 5d87fd8 + 2618401 commit 09d050e

File tree

3 files changed

+121
-121
lines changed

3 files changed

+121
-121
lines changed

1-js/12-generators-iterators/1-generators/01-pseudo-random-generator/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ alert(generator.next().value); // 282475249
1616
alert(generator.next().value); // 1622650073
1717
```
1818

19-
Please note, the same can be done with a regular function, like this:
19+
Tenga en cuenta que se puede hacer lo mismo con una función regular, como esta:
2020

2121
```js run
2222
function pseudoRandom(seed) {
@@ -35,4 +35,4 @@ alert(generator()); // 282475249
3535
alert(generator()); // 1622650073
3636
```
3737

38-
That also works. But then we lose ability to iterate with `for..of` and to use generator composition, that may be useful elsewhere.
38+
Eso también funciona. Pero entonces perdemos la capacidad de iterar con `for..of` y usar la composición del generador, que puede ser útil en otros lugares.

1-js/12-generators-iterators/1-generators/01-pseudo-random-generator/task.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11

2-
# Pseudo-random generator
2+
# Generador pseudoaleatorio
33

4-
There are many areas where we need random data.
4+
Hay muchas áreas en las que necesitamos datos aleatorios.
55

6-
One of them is testing. We may need random data: text, numbers, etc. to test things out well.
6+
Uno de ellos es para testeo. Es posible que necesitemos datos aleatorios: texto, números, etc. para probar bien las cosas.
77

8-
In JavaScript, we could use `Math.random()`. But if something goes wrong, we'd like to be able to repeat the test, using exactly the same data.
8+
En JavaScript, podríamos usar `Math.random()`. Pero si algo sale mal, nos gustaría poder repetir la prueba utilizando exactamente los mismos datos.
99

10-
For that, so called "seeded pseudo-random generators" are used. They take a "seed", the first value, and then generate the next ones using a formula so that the same seed yields the same sequence, and hence the whole flow is easily reproducible. We only need to remember the seed to repeat it.
10+
Para eso, se utilizan los denominados "generadores pseudoaleatorios con semilla". Toman una "semilla" como primer valor, y luego generan los siguientes utilizando una fórmula; a partir de la misma semilla se produce la misma secuencia y así todo el flujo es fácilmente reproducible. Solo necesitamos recordar la semilla para repetirla.
1111

12-
An example of such formula, that generates somewhat uniformly distributed values:
12+
Un ejemplo de dicha fórmula, que genera valores distribuidos de manera algo uniforme:
1313

1414
```
1515
next = previous * 16807 % 2147483647
1616
```
1717

18-
If we use `1` as the seed, the values will be:
18+
Si nosotros usamos `1` como semilla, los valores serán:
1919
1. `16807`
2020
2. `282475249`
2121
3. `1622650073`
22-
4. ...and so on...
22+
4. ...y así...
2323

24-
The task is to create a generator function `pseudoRandom(seed)` that takes `seed` and creates the generator with this formula.
24+
La tarea es crear una función generadora `pseudoRandom (seed)` que toma `seed` y crea el generador con esta fórmula.
2525

26-
Usage example:
26+
Ejemplo de uso
2727

2828
```js
2929
let generator = pseudoRandom(1);

0 commit comments

Comments
 (0)