- From: Tab Atkins Jr. via GitHub <sysbot+gh@w3.org>
- Date: Tue, 21 Jun 2022 17:27:47 +0000
- To: public-css-archive@w3.org
> Regarding the custom ident, would there be a way, if I declared a custom random() value to sometimes re-run that randomization equation again and other times use the same value, likely reaching for CSS vars? Yes, if you change the ident you'll get a different value. You can pipe the ident in via a var(), so you can declare it on the root to make it easy to edit in script. > /* will `var(--random-val-1)` and `var(--random-val-2)` always be equal? */ Yes, in that example both functions end up, after substitution, with the exact same arguments, so they'll always produce identical results. > /* will `var(--random-val-3)` be computed separately from 1 & 2 and thus possibly be different? */ Yes, it'll be an unrelated random value. > /* do different random function instances with the same ident produce different values when their values are different? in other words, are they only ensured to be the same when both the ident and the values are exactly equal */ Yes, they'll be different. I specify the cache depends on the min/max values as well because otherwise results end up correlated if you reuse a single ident - `random(foo, 1, 3, by 1)` and `random(foo, 1, 5, by 1)` would reveal the underlying random result's divisibility by 15, for example. This avoids confusing situations like what your example shows - the integer is probably going to be produced as some *large* integer that's then modulo'd into the appropriate range, so just because one instance from 1-5 returns, say, a "3", that's no guarantee that the exact same random seed would produce a "3" in a 1-7 range. Also, I think it's useful to authors to not require them to use unique idents *every* time, only when it's actually needed to force separate values. > /* can idents be numbers or even lengths? what types are permitted? */ No, they're [custom idents](https://andreubotella.com/csswg-auto-build/css-values-4/#custom-idents). > /* could the ident be omitted in place of per-element? */ I wouldn't let them be omitted *just* for a per-element case, but allowing them to be omitted *in general* is probably fine - they'll essentially just use an empty ident for caching. I'll have to fiddle with the grammar to get that to work, tho; probably change it to be `random( [ seed <custom-ident> || per-element ]? , ...)` so I can tell the cases apart. > /* is there ever a case when an ident could be omitted? how would the bottom example be handled? would it be invalid since the `1` would be registered as the ident, and 10 as the start value, with no end value */ Per my preceding post it would be invalid - `1` isn't an identifier. But per my immediately preceding quote response, it's probably fine to allow the ident to be omitted so `random(1, 10)` would work. (It'll just always return the same value everywhere it's used, same as `random(seed foo, 1, 10)` would return the same value everywhere it's used.) -- GitHub Notification of comment by tabatkins Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/2826#issuecomment-1162053915 using your GitHub account -- Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Tuesday, 21 June 2022 17:27:48 UTC