Re: [csswg-drafts] [css-values] random() function (#2826)

@tabatkins Thank you for the thoughtful consideration and feedback, and for clarifying your [original proposal](https://github.com/w3c/csswg-drafts/issues/2826#issuecomment-455347714) above. I really appreciate it and agree on all accounts.

I would love to see native `round()` and `nth()` functions make it into CSS and the implications that could be on a greater scale, though I definitely see great value in much of that calculation happening under the hood for `random()` and `random-pick()`, as you elaborated upon.

A couple of questions I still have—
* This is likely a question for a separate thread, though I'll pose it here first for clarification—
  Regarding supported semicolon-delimited lists in the proposed `nth()` function, I see some risk in using a semicolon as a delimiter, as that is also the termination symbol used to separate CSS properties within a style declaration. What if we instead opted for a yet unused symbol, but another common delimiter, such as the pipe symbol (`|`). Pipe delimiters are common in data and could be a worthwhile alternative for this.
  
  I'm sure much thought has already been put into that, but I'm just curious as to the reasoning and if there is still time to consider an alternative symbol for the spec, prior to implementation. Thanks!
* 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?

I have several other implementation questions regarding the spec, so I thought it best to include them within examples. Would you mind letting me know if my below assumptions are correct/incorrect, just so I can better understand the proposal?
```css
:root {
  /* would CSS vars be the proper approach to conditionally re-randomize? */
  --random-values: 1, 10;
  --ident: foo;

  /* will `var(--random-val-1)` and `var(--random-val-2)` always be equal? */
  --random-val-1: random(foo, var(--random-values)); /* 7, initial */
  --random-val-2: random(var(--ident), var(--random-values)); /* 7, same? */

  /* will `var(--random-val-3)` be computed separately from 1 & 2 and thus possibly be different? */
  --random-val-3: random(bar, var(--random-values)); /* possibly different? */

  /* 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 */
  --random-val-4: random(foo, 1, 11); /* also 7, or new random number? */

  /* can idents be numbers or even lengths? what types are permitted? */
  --random-val-5: random(1, var(--random-values)); /* 8 */

  /* could the ident be omitted in place of per-element? */
  --random-val-6: random(per-element, var(--random-values)); /* 1, initial */
  --random-val-7: var(--random-val-2); /* possibly different? */

  /* 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 */
  --random-val-8: random(var(--random-values)); /* 1, initial */
}

/* are idents respected for sibling elements (render order) or per the cascase (desc order)? */
#elem-1,
#elem-1 + #elem-2 {
  --random-val-1: random(foo, 1, 10); /* same for both */
  --random-val-2: random(foo per-element, 1, 10); /* possibly different for both? */
}
```

Thank you again! I really like the way you laid out the spec, and I hope this can find its way into CSS before too long 🙌🏼

-- 
GitHub Notification of comment by brandonmcconnell
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/2826#issuecomment-1161051353 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 01:29:31 UTC