Giter VIP home page Giter VIP logo

go-randomdata's People

Contributors

angelynz95 avatar bjacokes avatar bluele avatar briansorahan avatar clsung avatar daisy1754 avatar denisnikulin avatar ericfialkowski avatar excal04 avatar ezeql avatar haya14busa avatar joseustra avatar marksonghurst avatar muety avatar mxschmitt avatar natolumin avatar novln avatar p4tin avatar pallinder avatar pavel-main avatar rick1125 avatar sandrom avatar shamsher31 avatar wolfmetr avatar zier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-randomdata's Issues

Feature Request: Random sentence

Hi,
Could you add a sentence generator?When generating some articles ,title and content are needed,content can be generated by randomdata.Paragraph(),but I don't find which one should be used for generating title.

For example:

// Print a sentence
fmt.Println(randomdata.Sentence())

Randomiser seed

I noticed that you explicitly do rand.Seed(time.Now().UnixNano()) in each call to randomFrom.

Sometimes it is desirable to have a fixed seed for more reliable and predictable unit tests behaviour. Would it be possible to seed the randomiser only once, during package init and store the used seed? Additionally add a function that allows one to manually set the seed. Something like:

var seed int64

func Seed() int64 {
    return seed
}

func SetSeed(v int64) {
    seed = v
    rand.Seed(v)
}

func init() {
   SetSeed(time.Now().UnixNano())
}

Custom Seed (and Client Struct)

followup to #67

package level globals is a bit of an antipattern, but can definitely be used for simplified use cases. In the case of tests and parallelism and reproducibility, I'd prefer if I had a randomdata.New() that I could rely on, with an optional input variable of the random seed.

Thanks!

Low variety output of randomdata.Paragraph()

randomdata.Paragraph()
Seems to output very often almost the same sentance .
It would be good if we could have a bigger variety.

For example when testing big data , with full text search, having more words to scan would be nice

randomdata.FullDate() can return invalid dates

I leverage the randomdata.FullDate() function call in some unit tests by parsing the random full dates into time.Time structs. :

			t, err = time.Parse(dateLayout, randomdata.FullDate())
			if err != nil {
				Fail(err.Error())
			}

What I expected to see : The above fail handler would not be called

What I actually saw : parsing time "Tuesday 29 Feb 2018": day out of range

This causes intermittent unit test failures.

long running use, can cause an array out of bounds exception

goroutine 9 [running]:
math/rand.(*rngSource).Uint64(...)
	/usr/local/Cellar/go/1.10.3/libexec/src/math/rand/rng.go:246
math/rand.(*rngSource).Int63(0xc4200a5500, 0xc4202e8bd0)
	/usr/local/Cellar/go/1.10.3/libexec/src/math/rand/rng.go:231 +0x8a
math/rand.(*Rand).Int63(0xc420094510, 0x4)
	/usr/local/Cellar/go/1.10.3/libexec/src/math/rand/rand.go:82 +0x33
math/rand.(*Rand).Int31(0xc420094510, 0x4)
	/usr/local/Cellar/go/1.10.3/libexec/src/math/rand/rand.go:96 +0x2b
math/rand.(*Rand).Int31n(0xc420094510, 0x20f, 0x0)
	/usr/local/Cellar/go/1.10.3/libexec/src/math/rand/rand.go:131 +0x4f
math/rand.(*Rand).Intn(0xc420094510, 0x20f, 0x0)
	/usr/local/Cellar/go/1.10.3/libexec/src/math/rand/rand.go:169 +0x45
github.com/jayunit100/vuln-sim/vendor/github.com/Pallinder/go-randomdata.randomFrom(0xc4200d0000, 0x20f, 0x2c7, 0x0, 0xc4202e8b48)
	/Users/jayunit100/go/src/github.com/jayunit100/vuln-sim/vendor/github.com/Pallinder/go-randomdata/random_data.go:84 +0x37
github.com/jayunit100/vuln-sim/vendor/github.com/Pallinder/go-randomdata.Adjective(0xc4200192d8, 0x4)
	/Users/jayunit100/go/src/github.com/jayunit100/vuln-sim/vendor/github.com/Pallinder/go-randomdata/random_data.go:262 +0x45
github.com/jayunit100/vuln-sim/vendor/github.com/Pallinder/go-randomdata.SillyName(0x7ffffff7010ae51b, 0xc4202e8c68)
	/Users/jayunit100/go/src/github.com/jayunit100/vuln-sim/vendor/github.com/Pallinder/go-randomdata/random_data.go:279 +0x44
github.com/jayunit100/vuln-sim/pkg/model3.randApp(0xa, 0xc420106080, 0xc4202e8d20, 0x1011519, 0xc5f68aade0)
	/Users/jayunit100/go/src/github.com/jayunit100/vuln-sim/pkg/model3/simulator.go:154 +0x26
github.com/jayunit100/vuln-sim/pkg/model3.(*ClusterSim).initEvents.func1(0xc4200a92c0, 0xc5f68aade0, 0xc4202e8e88, 0x4, 0xc5f68a1500)
	/Users/jayunit100/go/src/github.com/jayunit100/vuln-sim/pkg/model3/simulator.go:230 +0x22e
github.com/jayunit100/vuln-sim/pkg/model3.(*ClusterSim).initEvents(0xc4200a92c0, 0xc422f7a060, 0xc4239619c0, 0xa)
	/Users/jayunit100/go/src/github.com/jayunit100/vuln-sim/pkg/model3/simulator.go:236 +0x59d
github.com/jayunit100/vuln-sim/pkg/model3.(*ClusterSim).Initialize(0xc4200a92c0)
	/Users/jayunit100/go/src/github.com/jayunit100/vuln-sim/pkg/model3/simulator.go:203 +0x1c6
github.com/jayunit100/vuln-sim/pkg/model3.(*ClusterSim).Simulate(0xc4200a92c0, 0x0)
	/Users/jayunit100/go/src/github.com/jayunit100/vuln-sim/pkg/model3/simulator.go:376 +0x34
main.ExperimentalSimulation1.func1(0xc42008a6c0, 0xc4200a92c0)
	/Users/jayunit100/go/src/github.com/jayunit100/vuln-sim/clustersim/main.go:106 +0x2b
created by main.ExperimentalSimulation1
	/Users/jayunit100/go/src/github.com/jayunit100/vuln-sim/clustersim/main.go:105 +0x122

Random number generator unreliable

Hi,

I've seen you are using math/rand, which causes diversity and gender quota issues ;-)

  • I often ended up with the same gender
  • I often had collisions, with the same names being chosen in a row

I suggest changing random number generation from

		import "math/rand"

		// ...

		g := rand.Intn(2)

to

		import "crypto/rand"

		// ...

		n, _ := rand.Int(rand.Reader, big.NewInt(2))
		g := int(n.Int64())

(Respectively, something similar in func randomFrom(...))

I could mitigate the gender selection by generating the random number myself, but the name for that gender is then still decided by internals and not properly random, often causing the same name in a row.

Seeder bug on Windows, returns same numbers

While executing this operation multiple times on Windows 8.1 x64:

fmt.Println(StringNumber(4, "-"))

I get strange results:

44-44-44-44
55-55-55-55
11-11-11-11
00-00-00-00

If we look at seedAndReturnRandom() function, we can find:

rand.Seed(time.Now().UnixNano())

This probably happens because golang executes faster than nanosecond passes. Should we sleep for a while before seeding, implement different seeding algorithm or it's a platform-specific bug?

P.S. My co-worker launched this test on Gentoo, and it works properly.

Feature Request: Random string from a list

Hello:

Can you add a function when given a slice of strings, will return one of them at random? Suppose the new function signature looks like String(stringList ...string) string. Then, one of the strings in the given list is returned at random.

Here is an example invocation:

myString := randomdata.String("foo", "bar", "baz")

Thank you,

Evan McClure

ipv6 address randomness is too small

Hi!
Not good idea to use rand.Seed(time.Now().UnixNano()) when generate IPv6 address.
As result: IpAddress : 6363:6363:6363:6363:6363:6363:6363:6363
Please transfer rand.Seed(time.Now().UnixNano()) to init func.

func seedAndReturnRandom(n int) int {
	rand.Seed(time.Now().UnixNano())
	return rand.Intn(n)
}

// Returns a valid IPv6 address as net.IP
func IpV6Address() string {
	var ip net.IP
	for i := 0; i < net.IPv6len; i++ {
		number := uint8(seedAndReturnRandom(255))
		ip = append(ip, number)
	}
	return ip.String()
}

https://github.com/Pallinder/go-randomdata/blob/master/random_data.go#L67

Title with RandomGender generates firstname instead of Title

See below the bug in default switch.

// Title returns a random title, gender decides the gender of the name
func Title(gender int) string {
	var title = ""
	switch gender {
	case Male:
		title = randomFrom(jsonData.MaleTitles)
		break
	case Female:
		title = randomFrom(jsonData.FemaleTitles)
		break
	default:
		title = FirstName(privateRand.Intn(2))
		break
	}
	return title
}

Library versioning

It's kinda odd to see a cool library still not being versioned even though it seems to have been around for 5 years already and going through a decent evolution.

Please consider:

This would greatly improve the library user experience and the seriousness of the project by allowing the user to achieve reproducible builds when using dep for example.

Currently, there seems to be no guarantee on backward-compatibility so the current release would need to start with 0.1 according to semver, though if it's already production ready then start with 1.0 right away.

This issue is loosely related to #47

make email more random

I'm currently using this package for test fixture generation
and it happens quite often that i get the same email in just few repetitive calls, which prevents from using it 'as is' and requiring to add some random part manually.

the func of Number exists a bug!

panic: runtime error: index out of range

goroutine 28 [running]:
math/rand.(*rngSource).Uint64(...)
/usr/local/share/go/src/math/rand/rng.go:249
math/rand.(*rngSource).Int63(0xc0000c9500, 0x4f95066a366ef45d)
/usr/local/share/go/src/math/rand/rng.go:234 +0x89
math/rand.(*Rand).Int63(0xc0000aa4e0, 0x7ffffffe78bb7a00)
/usr/local/share/go/src/math/rand/rand.go:85 +0x33
math/rand.(*Rand).Int31(0xc0000aa4e0, 0x1e)
/usr/local/share/go/src/math/rand/rand.go:99 +0x2b
math/rand.(*Rand).Int31n(0xc0000aa4e0, 0xe0000001e, 0x0)
/usr/local/share/go/src/math/rand/rand.go:134 +0x4f
math/rand.(*Rand).Intn(0xc0000aa4e0, 0x1e, 0x14d)
/usr/local/share/go/src/math/rand/rand.go:172 +0x45
github.com/Pallinder/go-randomdata.Number(0xc000297ea8, 0x2, 0x2, 0x1e)
/usr/local/share/gopath/src/github.com/Pallinder/go-randomdata/random_data.go:225 +0x83
github.com/Pallinder/go-randomdata.FullDate(0x411703e3289fc8f6, 0x45)
/usr/local/share/gopath/src/github.com/Pallinder/go-randomdata/random_data.go:358 +0x10d

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.