I need to generate a guid to use in an api that my service integrates with. It won’t be catastrophic if my guid isn’t unique. I only need to generate a couple dozen at most and I can use a hash to make sure they are unique. I tried using SecureRandom, but on my machine it freezes SketchUp for 24 seconds on the first use, after that it is fast. Does anyone know of another solution?
require 'securerandom'
t = Time.now
uuid = SecureRandom.uuid
"#{Time.now - t} seconds to generate guid."
Why not generate several uuids and then store them in your RB file’s code - as strings in an array of say 50 uuid elements.
You say it’s not that important they’re unique anyway…
So I assume reusing one sometimes is acceptable ?
Later on you can access them ‘at random’ using rnd() to pick one from your array…
You could even randomize the uuid further by using ‘next’ on it a random number of iterations, that way you’ll very rarely repeat…
The source of this is how the underlying OpenSSL is seeding it’s random bytes. On Windows it’s been doing so using deprecated debug API from the Win32 API that’s only gotten slower over the years. There’s been work towards fixing that and I thought it was picked up by Ruby and SketchUp by now. I would have to dig into my old notes to find what versions were affected.)