strings: add lorum Markov chain text generator #26387
Conversation
|
Just curious... why change lorem to lorum ? |
That was a goof. Fixed it up in the most recent commit. |
| t := time.now().unix_milli() | ||
| rand.seed([u32(t), u32(t >> 32)]) | ||
| rng_seed = rand.int() |
There was a problem hiding this comment.
| t := time.now().unix_milli() | |
| rand.seed([u32(t), u32(t >> 32)]) | |
| rng_seed = rand.int() | |
| rng_seed = rand.int() |
There was a problem hiding this comment.
the default random number generator is already time seeded by default
| @@ -0,0 +1,66 @@ | |||
| module lorem | |||
There was a problem hiding this comment.
| module lorem | |
| import strings.lorem |
| @@ -0,0 +1,66 @@ | |||
| module lorem | |||
There was a problem hiding this comment.
| module lorem | |
| import strings.lorem |
Turning this into a normal (non-internal) test, has the benefit that all of the tests also become usage examples, and as a user, you can also more easily see, what the public (and well tested) APIs are.
There was a problem hiding this comment.
afaik only lorem_vary and lorem_tokenize are tested here, and are private?
spytheman
left a comment
There was a problem hiding this comment.
Excellent work.
@mike-ward thank you 🙇🏻 .
|
Thanks guys. I thought I had done my due diligence to make this easy to merge. I'll do better next time... |
This PR integrates
lorumintovlib/strings, refining the implementation to be suitable for the standard library.Changes:
randdependency: Implements a simple internal LCG (Linear Congruential Generator) to handle pseudo-randomness. This prevents circular dependencies (e.g.,strings->rand->time), which is critical forvlibcore modules.lorem_generate()tolorum()for consistency with the file name and conciseness.examples/lorem.vto use the newstrings.lorum()API. The example now handles random seeding explicitly usingrandandtimeto maintain the expected CLI behavior (random output by default).Verification:
v test vlib/strings/lorum_test.vpasses.v run examples/lorem.vruns successfully and produces varied output.