bricabrac-single-file-modules
v0.14.0
Published
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
Readme
Table of Contents generated with DocToc
Bric-A-Brac Standard Brics
To Do
Random
[—]Provide alternative to ditchedunique, such as filling aSetto a certain size with characters[—]Provide internal implementations that capture attempt counts for testing, better insights[—]use custom class forstatsthat handles excessive retry counts[—]implement iterators[—]shouldon_exhaustion,on_stats,max_retriesbe implemented for each method?
Random: Implementation Structure
the library currently supports four data types to generate instance values for:
float,integer,chr,textfor each case, instance values can be produced...
- ...that are not smaller than a given
minimum and not larger than a givenmaximum - ...that are
filtered according to a given RegEx pattern or an arbitrary function - ...that, in the case of
texts, are not shorter and not longer than a given pair ofminimum_lengthandmaximum_length - ...that are unique in relation to a given collection (IOW that are new to a given collection)
- ...that are not smaller than a given
the foundational Pseudo-Random Number Generator (PRNG) that enables the generation of pseudo-random values is piece of code that I found on the Internet (duh), is called SplitMix32 and is, according to the poster,
A 32-bit state PRNG that was made by taking MurmurHash3's mixing function, adding a incrementor and tweaking the constants. It's potentially one of the better 32-bit PRNGs so far; even the author of Mulberry32 considers it to be the better choice. It's also just as fast.
Like JavaScript's built-in
Math.random()generator, this PRNG will generate evenly distributed valuestbetween0(inclusive) and1(exclusive) (i.e.0 < t ≤ 1), but other thanMath.random(), it allows to be given aseedto set its state to a known fixed point, from whence the series of random numbers to be generated will remain constant for each instantiation. This randomly-deterministic (or deterministically random, or 'random but foreseeable') operation is valuable for testing.Since the random core value
t(accessible asGet_random::_float()) is always in the interval[0,1), it's straightforward to both scale (stretch or shrink) it to any other length[0,p)and / or transpose (shift left or right) it to any other starting point[q,q+1), meaning it can be projected into any interval[min,max)by computingj = min + ( t * ( max - min ) ). That projected valuejcan then be rounded e.g. to an integer numbern, and that integerncan be interpreted as a Unicode Code Point and be used inString.fromCodePoint()to obtain a 'character'. Since many Unicode codepoints are unassigned or contain control characters,Get_randommethods will filter codepoints to include only 'printable' characters. Lastly, characters can be concatenated to strings which, again, can be made shorter or longer, be built from filtered codepoints from a narrowed set like, say,/^[a-zA-ZäöüÄÖÜß]$/(most commonly used letters to write German), or adhere to some predefined pattern or other arbitrary restrictions. It all comes out of[0,1)which I find amazing.A further desirable restriction on random values that is sometimes encountered is the exclusion of duplicates;
Get_randomcan help with that.each type has dedicated methods to produce instances of each type:
- a convenience function bearing the name of the type:
Get_random::float(),Get_random::chr()and so on. These convenience functions will call the associated 'producer methods'Get_random::float_producer(),Get_random::chr_producer()and so on which will analyze the arguments given and return a function that in turn will produce random values according to the specs indicated by the arguments.
- a convenience function bearing the name of the type:
References
To Do
[—]implement a 'raw codepoint' convenience method?[—]adaptGet_random::float(),Get_random::integer()to matchGet_random::chr(),Get_random::text()[—]ensureGet_random::cfgon_statsis called when given even when missing ornullin method call[—]need betterrpr()[—]onerpr()for use in texts such as error messages, onerpr()('show()'?) for use in presentational contexts
Benchmark
[—]implement ?min_count/ ?max_count/ ?min_dt/ ?max_dt,prioritize: ( 'dt' | 'count' )- probably best to stick with
minormaxfor bothcountanddt
- probably best to stick with
Errors
[—]custom error base class[—]or multiple ones, each derived from a built-in class such asRangeError,TypeError,AggregateError
[—]solution to capture existing error, issue new one a la Python'sraise Error_2 from Error_1[—]omit repeated lines when displayingerror.cause?
Remap
[—]provide facility to retrieve all own keys (strings+symbols)[—]use property descriptors[—]can be expanded to provideshallow_clone(),deep_clone()
Other
[—]publishclean()solution to the 'Assign-Problem with Intermediate Nulls and Undefineds' in the context of a Bric-A-Brac SFModule
