All Projects → fakedata-haskell → Fakedata

fakedata-haskell / Fakedata

Licence: other
Haskell Library for producing quality fake data

Programming Languages

haskell
3896 projects

Projects that are alternatives of or similar to Fakedata

Gofakeit
Random fake data generator written in go
Stars: ✭ 2,193 (+1758.47%)
Mutual labels:  fake, random
random
Random data generator AKA faker
Stars: ✭ 14 (-88.14%)
Mutual labels:  random, fake
falso
All the Fake Data for All Your Real Needs 🙂
Stars: ✭ 877 (+643.22%)
Mutual labels:  random, fake
Eth Random
commit-reveal RNG method in Ethereum
Stars: ✭ 79 (-33.05%)
Mutual labels:  random
Openapi Sampler
🔠 Tool for generation samples based on OpenAPI(fka Swagger) payload/response schema
Stars: ✭ 83 (-29.66%)
Mutual labels:  fake
Impersonator
Ruby library to record and replay object interactions
Stars: ✭ 100 (-15.25%)
Mutual labels:  fake
Creak
Poison, reset, spoof, redirect MITM script
Stars: ✭ 116 (-1.69%)
Mutual labels:  fake
Random Word
This is a simple python package to generate random english words
Stars: ✭ 75 (-36.44%)
Mutual labels:  random
Hyperapp Fx
Effects for use with Hyperapp
Stars: ✭ 105 (-11.02%)
Mutual labels:  random
Octo
A fuzzing library in JavaScript. ✨
Stars: ✭ 96 (-18.64%)
Mutual labels:  random
Weightedrand
⚖️ Fast weighted random selection for Go
Stars: ✭ 96 (-18.64%)
Mutual labels:  random
Randomcolor
Javascript module for generating random, distinguishable, pleasing colors (ie: for chart series).
Stars: ✭ 83 (-29.66%)
Mutual labels:  random
Prob.js
Generate random numbers from different probability distributions.
Stars: ✭ 102 (-13.56%)
Mutual labels:  random
Birdseed
🐦 🎲 Use Twitter's Search API to get random numbers
Stars: ✭ 81 (-31.36%)
Mutual labels:  random
Rando Php
RandoPhp is a open source library that implements random generators (Integer, Char, Byte, Sequences, Boolean) and take random sample from arrays
Stars: ✭ 107 (-9.32%)
Mutual labels:  random
Spicy Proton
Generate a random English adjective-noun word pair in Ruby
Stars: ✭ 76 (-35.59%)
Mutual labels:  random
Faker Cli
cli wrapper for fakerjs
Stars: ✭ 104 (-11.86%)
Mutual labels:  fake
Sns
Fake Amazon SNS
Stars: ✭ 94 (-20.34%)
Mutual labels:  fake
Keygen Php
A fluent PHP random key generator.
Stars: ✭ 93 (-21.19%)
Mutual labels:  random
Faker
A library for generating fake data such as names, addresses, and phone numbers.
Stars: ✭ 9,638 (+8067.8%)
Mutual labels:  fake

fakedata Hackage Stackage Nightly Stackage LTS Build Status

Table of Contents

fakedata

This library is a port of Ruby's faker. It's a library for producing fake data such as names, addressess and phone numbers. Note that it directly uses the source data from that library, so the quality of fake data is quite high!

Tutorial

Generating address

~/g/fakedata (master) $ stack ghci
λ> import Faker
λ> import Faker.Address
λ> address <- generate fullAddress
λ> address
"Apt. 298 340 Ike Mission, Goldnertown, FL 19488-9259"

Generating name

λ> fullName <- generate name
λ> fullName
"Sherryl Steuber"

Generate quotes from the movie Back to the Future

λ> import Faker.Movie.BackToTheFuture
λ> import Faker.Combinators
λ> qs <- generateNonDeterministic $ listOf 5 quotes
λ> qs
[ "Yes. Yes. I'm George. George McFly. I'm your density. I mean, your destiny."
, "Hello? Hello? Anybody home? Huh? Think, McFly. Think! I gotta have time to get them retyped. Do you realize what would happen if I hand in my reports in your handwriting? I'll get fired. You wouldn't want that to happen, would ya? Would ya?"
, "Lorraine. My density has brought me to you."
, "See you in about 30 years."
, "You really think I ought to swear?"
]

Combining Fake datas

{-#LANGUAGE RecordWildCards#-}

import Faker
import Faker.Name
import Faker.Address
import Data.Text

data Person = Person {
    personName :: Text,
    personAddress :: Text
} deriving (Show, Eq)

fakePerson :: Fake Person
fakePerson = do
    personName <- name
    personAddress <- fullAddress
    pure $ Person{..}

main :: IO ()
main = do
    person <- generate fakePerson
    print person

And on executing them:

$ stack name.hs
Person
  { personName = "Sherryl Steuber"
  , personAddress = "Apt. 298 340 Ike Mission, Goldnertown, FL 19488-9259"
  }

You would have noticed in the above output that the name and address are the same as generated before in the GHCi REPL. That's because, by default all the generated data are deterministic. If you want a different set of output each time, you would have to modify the random generator output:

main :: IO ()
main = do
    gen <- newStdGen
    let settings = setRandomGen gen defaultFakerSettings
    person <- generateWithSettings settings fakePerson
    print person

And on executing the program, you will get a different output:

Person
  { personName = "Ned Effertz Sr."
  , personAddress = "Suite 158 1580 Schulist Mall, Schulistburgh, NY 15804-3392"
  }

The above program can be even minimized like this:

main :: IO ()
main = do
    let settings = setNonDeterministic defaultFakerSettings
    person <- generateWithSettings settings fakePerson
    print person

Or even better:

main :: IO ()
main = do
    person <- generateNonDeterministic fakePerson
    print person

Combinators

listOf

λ> import Faker.Address
λ> item <- generateNonDeterministic $ listOf 5 country
λ> item
["Ecuador","French Guiana","Faroe Islands","Canada","Armenia"]

oneOf

λ> item <- generate $ oneof [country, fullAddress]
λ> item
"Suite 599 599 Brakus Flat, South Mason, MT 59962-6876"

suchThat

λ> import qualified Faker.Address as AD
λ> item :: Text <- generate $ suchThat AD.country (\x -> (T.length x > 5))
λ> item
"Ecuador"
λ> item :: Text <- generate $ suchThat AD.country (\x -> (T.length x > 8))
λ> item
"French Guiana"

For seeing the full list of combinators, see the module documentation of Faker.Combinators.

Comparision with other libraries

There are two other libraries in the Hackage providing fake data:

The problem with both the above libraries is that the library covers only a very small amount of fake data source. I wanted to have an equivalent functionality with something like faker. Also, most of the combinators in this packages has been inspired (read as taken) from the fake library. Also, fakedata offers fairly good amount of support of different locales. Also since we rely on an external data source, we get free updates and high quality data source with little effort. Also, it's easier to extend the library with it's own data source if we want to do it that way.

Acknowledgments

Benjamin Curtis for his Ruby faker library from which the data source is taken from.

Icons made by Freepik from Flaticon.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].