Rolling the dice with CSS random()

(webkit.org)

103 points | by zdw 3 days ago ago

11 comments

  • demurgos 38 minutes ago ago

    Where is the spec? I can't find an entry on MDN.

    Is there a way to get reproducibility? In the same browser or across browsers? Even if it's not the default mode.

  • Tepix 4 hours ago ago

    Related: Animated starfield in pure CSS

    https://codepen.io/ArneSava/pen/BaWxOaR

  • gherkinnn 7 hours ago 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 7 hours ago ago

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

      • akdev1l 3 hours ago ago

        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()

      • tsujp 4 hours ago ago

        JS also has Crypto.getRandomValues()

  • kachapopopow 3 hours ago ago

    I yern for the day we can have react-type pages without any javascript. Keep chugging webkit I believe in you.

  • jvdvegt 5 hours ago ago

    Nice but... no dice!

  • hannob 2 hours ago ago

    Having seen too many "this randomness function was never meant to be used for security, but people use it for security anyway" vulnerabilities in the past:

    Can we PLEASEPLEASEPLEASE have this secure by default from the beginning?

    • 1718627440 an hour ago ago

      Security in the Stylesheet? Come on, you need to set boundaries for expectable use.