Remix.run Logo
gherkinnn 4 days ago

Nice. Currently I have to set CSS custom properties with JS to achieve the same effect.

Wonderful to see how CSS gets a usable random function before JS does.

noman-land 4 days ago | parent | next [-]

Maybe "usable" is your qualifier but what's wrong with Math.random()?

akdev1l 4 days ago | parent | next [-]

To generate random number in a specific range you need to do something I always forget and need to google.

    Math.floor(Math.random() * (max - min + 1)) + min;

(Google AI summary says this is the thing)

The CSS function would be random(min, max)

Also the CSS function seems to take a number of steps, it is not immediately obvious to me how to do that with Math.random()

sdenton4 4 days ago | parent | next [-]

Why not add a Math.randint?

I imagine there's some deep ideological war over whether to add more programming functionality to css...

ameliaquining 4 days ago | parent [-]

Currently under discussion in the standards committee: https://tc39.es/proposal-random-functions/

ameliaquining 4 days ago | parent | prev [-]

    Math.floor(Math.random() * Math.floor((max - min) / step)) * step + min
tsujp 4 days ago | parent | prev [-]

JS also has Crypto.getRandomValues()

ballenf 4 days ago | parent | prev [-]

So now we can add a random data prop to a hidden dom element, then query that from JS. You know, to make your JS random function simpler. ;)

gherkinnn 4 days ago | parent [-]

That was my second idea. I've done worse.