sunesimonsen / chance-generators Goto Github PK
View Code? Open in Web Editor NEWRandom generators based on changejs
Home Page: https://sunesimonsen.github.io/chance-generators/
License: MIT License
Random generators based on changejs
Home Page: https://sunesimonsen.github.io/chance-generators/
License: MIT License
After I've learned about the map
method of generators I'm slowly realizing that the mapper functions themselves are very powerful, reusable and composable. I feel we should encourage sharing of such functions, and maybe add some of the most useful ones to core.
We might also want to consider changing the API slightly. it always occurred to me as odd that it was OK to use a Generators
instance declared in an outer scope inside the mapper function body (probably because it looks like a side effect and mapper should be "pure"), for example:
var g = new Generators(424);
var equallyLongStrings = g.integer({min:0, max: 10}).map(function (n) {
return g.array(g.string({length: n}));
});
Would it be possible to eg. pass the Generators
instance to the mapper function as the second parameter? I think that would make it easier to put generator mappers into libraries.
It should be trivial to do.
Something like:
var number = g.pick([
g.integer({min: -100, max: 100}), g.integer,
g.floating({min: -100, max: 100}), g.floating
])
var stringNumber = number.map(function (v) { return String(v) })
var anyPrimitive = g.pick([number, g.string, g.pick([
-0, +0, 0, undefined, null, false, true,
NaN, Infinity, -Infinity, '', [], stringNumber,
Number.MAX_SAFE_INTEGER,
Number.MIN_SAFE_INTEGER,
Number.MAX_VALUE,
Number.MIN_VALUE
])])
var any = g.weighted([anyPrimitive, g.array(anyPrimitive)], [10, 1])
It should also be capable of generating random objects and nested arrays.
Minor nit but the GitHub project description is listed as:
Random generators based on changejs
It should be:
Random generators based on chance.js
Investigate if it is possible to shrink the producers by starting with an infinite cycle count. When the producer hits the max cycle count, it starts over.
When you need to shrink you take the current cycle and return a new producer with that as the max cycle count. That way we would shrink towards the beginning of the producer.
In previous release one had access to the Generators constructor where a seed value could be supplied. How does one accomplish the same in v3?
Also does one have access the chance instance, a getter or some other means?
Thanks in advance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.