andreyuhai
Any library that generates a random URL safe string with the same seed?
If we always use the same seed then we always get the same number with :rand.uniform(10). I was wondering whether we can do that with random strings as well, I mean obviously we can but I was wondering whether there’s already that functionality in any library.
Why I need it is that, I need to create an API, and you don’t keep any data anywhere except encoding into the API token. Given the same API token you always have to generate the same information every time, so I thought using seeds would be a good approach.
One of them is this gist which actually uses Enum.random.
Most Liked
stefanchrobot
Not responding directly to your question, but it sounds like you want to hash something rather than generate a random value. I’d suggest looking into Plug.Crypto and JWTs.
03juan
Simple generation of seeded, URL-safe strings (github.com)
Here is my attempt at modifying the gist for seeded generation. I took the liberty of simplifying the code a bit into a Livebook.
I don’t have any experience with :rand so I don’t know if you need to reset the seed generation to pseudo-random after generating in randomize/3, to prevent it affecting other parts of an application.
In my opinion it seems a bit overkill to create a whole library for this, but that’s not relevant to the question.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








