GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Generators by Nordtonito · Pull Request #224 · javascript-tutorial/uk.javascript.info

Generators #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
tarasyyyk merged 1 commit into javascript-tutorial:master from Nordtonito:master
Dec 1, 2021

Uh oh!

There was an error while loading. Please reload this page.

Merged

Generators #224

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
7a3cedd
Generators
Nordtonito Dec 1, 2021
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

4 changes: 2 additions & 2 deletions 4 1-js/12-generators-iterators/1-generators/01-pseudo-random-generator/solution.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ alert(generator.next().value); // 282475249
alert(generator.next().value); // 1622650073
```

Please note, the same can be done with a regular function, like this:
Зверніть увагу, те ж саме можна зробити зі звичайною функцією, наприклад:

```js run
function pseudoRandom(seed) {
Expand All @@ -35,4 +35,4 @@ alert(generator()); // 282475249
alert(generator()); // 1622650073
```

That also works. But then we lose ability to iterate with `for..of` and to use generator composition, that may be useful elsewhere.
Це також працює. Але тоді ми втрачаємо можливість перебору за допомогою `for..of` і використання композиції генераторів, що може бути корисною в інших випадках.
18 changes: 9 additions & 9 deletions 18 1-js/12-generators-iterators/1-generators/01-pseudo-random-generator/task.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@

# Pseudo-random generator
# Псевдовипадковий генератор

There are many areas where we need random data.
Є багато областей, де нам потрібні випадкові дані.

One of them is testing. We may need random data: text, numbers, etc. to test things out well.
Одна з них – тестування. Нам можуть знадобитися випадкові дані: текст, числа тощо, щоб добре все перевірити.

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.
У JavaScript ми можемо використовувати `Math.random()`. Але якщо щось піде не так, ми хотіли б мати можливість повторити тест, використовуючи точно ті самі дані.

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.
Для цього використовуються так звані "сіяні псевдовипадкові генератори". Вони беруть "зерно", перше значення, а потім генерують наступні за допомогою формули, так що те саме насіння дає ту саму послідовність, а отже, весь потік легко відтворюється. Нам потрібно лише згадати зерно, щоб повторити його.

An example of such formula, that generates somewhat uniformly distributed values:
Приклад такої формули, яка генерує рівномірно розподілені значення:

```
next = previous * 16807 % 2147483647
```

If we use `1` as the seed, the values will be:
Якщо ми використаємо `1` як зерно, то значення будуть такими:
Comment thread
Nordtonito marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

1. `16807`
2. `282475249`
3. `1622650073`
4. ...and so on...

The task is to create a generator function `pseudoRandom(seed)` that takes `seed` and creates the generator with this formula.
Завдання полягає в тому, щоб створити функцію-генератор `pseudoRandom(seed)`, яка приймає `seed` і створює генератор з цією формулою.

Usage example:
Приклад використання:

```js
let generator = pseudoRandom(1);
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.