Is there something like a now() function?

I would like to seed a random number generator ‘randomly’ , total randomness is not required.

Is there a way of specifying the number of seconds between a certain date (epoch in particular) and now? datetime.today() doesn’t have seconds. That would be good enough for my purposes.

Thanks

1 Like

Have you had a look at suiji?

I think they mean for seeding suiji.

I’m pretty sure that doesn’t exist, and I kinda question the usefulness. What is your usecase? I would guess you want to export the same document multiple times, each with their own variations. Then I assume you’re not pressing “download” multiple times in the web app, i.e. you have Typst installed locally. On the CLI, you can just use --input: Can I configure my document (e.g. draft/release version, color theme) when creating a PDF without modifying the Typst file directly?

I think that’s a sensible workaround, and I don’t think there is a lot of interest in adding now(): I barely use today() as I want my documents reproducible, and now() changes so often that I doubt people would really want to use it to get the time a document was created. There are of course documents that incorporate the creation time; those are generated automatically, so --input is again the solution.

The other use of now() is of course randomness as you describe. When previewing your document, that would decrease the benefits of incremental compilation while not really giving a benefit: in the end, you will only get one document anyway.

I’m of course open to being convinced otherwise, but that’s my current view on this matter :slight_smile:

1 Like

I am generating a realistically looking date stamp including smudged corners and want that to appear in a slightly random location and rotation (near the signature block of a letter).

Someone wrote a random generator in typst for me a while back (which is all I need, so haven’t figured out sujii yet) but currently I have to seed it by way of an imported file generated by Makefile which requires to do the compilation from the command line.

I rather would like to be able to do that also from within my editor (Sublime Text), ie just hit Command-B (compile it) and see the changed stamp.

Is the purpose of the regeneration to have each letter unique, or to have an easy way to try new instances of the randomized stamps? If it’s the latter, does it not bother you that a mistaken Command-B could replace a random stamp that you were happy with by one that doesn’t look as good, overwriting the previous file?

If it’s the former, maybe you can use the letter’s text to randomize the seed?

#show: body => body {
  rng-seed.update(f(body))
  body
}

Dear Jane,
...

The f(x) could be something similar to the “extract plain text” example here, just instead of actually returning the plain text you would use the letter’s unicode values to affect the seed.