tikotzky / faker-rs

A library for generating fake data such as names, addresses, and phone numbers.
28 stars 5 forks source link

fake data generation seed #8

Open matteosister opened 4 years ago

matteosister commented 4 years ago

is there a way to provide the generator with a seed, so that, given the same seed, I will always get the same fake data back?

I'm trying to mock an external web server, and I would like to return fake data based on a provided id.

Many thanks for the great lib!

nixpulvis commented 4 years ago

This is definitely doable, but I want to rethink the API for this crate a bit in the process...

Hopefully the general Faker interface wont need to change (much?), but I really don't like having Helpers in every structure, and it compounds the problem of passing around a seed everywhere. I don't expect this to be hard however.

Let me give some ideas a try and post an update later. Thanks for bringing this crate back to my attention.

nixpulvis commented 4 years ago

Well I've fixed the Helpers bit (aka removed them). But there's still a number of problems... Primarily that the Locale is duplicated in many places. This has nothing to do directly with this issue, however I believe I need to fix this first, since it may influence the API.

Both the locale and RNG seed are cases of the same sort of issue, which is state that needs to be set when Faker is created, and shared to the underlying structures. I think I want to leave the sub-structures (e.g. Address, Name, etc) mostly for organizational purposes, though since using them on their own doesn't make a lot of sense to me, perhaps removing them is a change in the API that should be implemented.