elm-uuid | Generate and parse UUIDs in Elm | Identity Management library
kandi X-RAY | elm-uuid Summary
kandi X-RAY | elm-uuid Summary
Note: this package has been forked with a few updates for 0.19 and is now maintained at: This package provides an opaque type for Uuids, helpers to serialize from and to String and helpers to generate new Uuids using Elm's Random package. Uuids are Universally Unique IDentifiers. They are 128 bit ids that are designed to be extremely unlikely to collide with other Uuids. This library only supports generating Version 4 Uuid (those generated using random numbers, as opposed to hashing. See Wikipedia on Uuids for more details). Version 4 Uuids are constructed using 122 pseudo random bits. Disclaimer: If you use this Library to generate Uuids, please be advised that it does not use a cryptographically secure pseudo random number generator. Depending on your use case the randomness provided may not be enough. The period of the underlying random generator is high, so creating lot's of random UUIDs on one client is fine, but please be aware that since the initial random seed of the current Random implementation is limited to 32 bits, creating UUIDs on many independent clients may lead to collisions more quickly than you think (see for details)! If you need to generate UUIDs on many clients independently, please use the fork which covers this case. This library is split into two Modules. Uuid wraps Uuids in an opaque type for improved type safety. If you prefer to simply get strings you can use the Uuid.Barebones module which provides methods to generate and verify Uuid as plain Strings.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of elm-uuid
elm-uuid Key Features
elm-uuid Examples and Code Snippets
Community Discussions
Trending Discussions on elm-uuid
QUESTION
I'm trying to generate random UUID's v4 within a loop:
...ANSWER
Answered 2021-Nov-19 at 10:40Generating random values is an effect and as such a pure language cannot just perform it.
However, there is a pure version of randomness, which is using random seeds. These have the property that every time you generate a value using the same seed, you get the same value - hence this is just a pure computation and is completely ok in a pure context.
Elm allows you to execute effects as Cmd
, the thing you return from your init
and update
functions. So one option you have is to always return Random.generate GotANewUUID UUID.generator
before you need it, then perform your computation when you handle the GotANewUUID
msg.
The other option is to keep track of the random seed. You either start with a deterministic one with Random.initialSeed
(probably not what you want with UUIDs, as they would be exactly the same on every run of your program), or in your init
function you return Random.generate GotNewSeed Random.independentSeed
. Then you store the seed in your model.
Every time you need to generate a new UUID, you use your newUuid
function above, making sure to store the new seed.
Here's an example:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install elm-uuid
Elm packages are available at elm-lang.org. If you are going to make HTTP requests, you may need elm/http and elm/json. You can get them set up in your project with the following commands: elm install elm/http and elm install elm/json. It adds these dependencies into your elm.json file, making these packages available in your project. Please refer guide.elm-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page