question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

generate a deterministic uuids using fast-check

See original GitHub issue

💬 Question and Help

I have the following code which I thought would generate a new uuid each time but in a deterministic fashion:

fc.configureGlobal({ seed: 0 });

export const generateUUID4 = (): string => {
  const Uuids = fc.sample(fc.uuidV(4), { numRuns: 1000 });
  const arb = fc
    .infiniteStream(fc.integer({ min: 0, max: 1000 }).noBias().noShrink())
    .map((s) => Uuids[s.next().value]);

  return fc.sample(arb)[0];
};

But this returns the same uuid each time.

The only way I can get it working is like this which is horrific with a global variable:

fc.configureGlobal({ seed: 0 });

const Uuids = fc.sample(fc.uuidV(4), { numRuns: 1000 });
let UuidCounter = 0;

export const generateUUID4 = (): string => {
  const next = Uuids[UuidCounter];

  UuidCounter++;

  return next;
};

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dagda1commented, Mar 2, 2021

@dubzzz thank you for taking the time to answer. I am not using your lib as intended but these are great answers.

Fast-check is totally awesome and I love how you are using generators. Generators are seriously underused in js.

Thank you, sir! This is great

0reactions
stale[bot]commented, May 1, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

fast-check/Arbitraries.md at main - GitHub
This documentation lists all the built-in arbitraries provided by fast-check . Please note that you can still create your own ones by either...
Read more >
Generate valid, deterministic UUIDs for tests - Stack Overflow
I am aware that UUIDs are by nature random and non-deterministic, and that this is good. That assumption is wrong.
Read more >
Unit tests for ORM with fast-check | Stas Shakirov
In this article, I am going to show how to use fast-check library to test ... Now we can generate any number of...
Read more >
[Solved]-Generate valid, deterministic UUIDs for tests-ruby
What you're trying to do seems like a testing anti-pattern. You could theoretically do what you want by using Version-1 UUIDs with a...
Read more >
The Magic of Generative Testing: Fast-Check in JavaScript
Generative testing (aka property testing), popularized by the Haskell library QuickCheck, is a technique of:- specifying invariant laws your ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found