Computer
Meet the Journalists Training AI Models for Meta and OpenAI
Read more of this story at Slashdot.
CodeSOD: Uniquely Expressed
Most of us, when generating a UUID, will reach for a library to do it. Even a UUIDv4, which is just a random number, presents challenges: doing randomness correctly is hard, and certain bits within the UUID are reserved for metadata about what kind of UUID we're generating.
But Gretchen's co-worker didn't reach for a library. What they did reach for was… regular expressions?
function uuidv4() { return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) { var r = (Math.random() * 16) | 0, v = c == "x" ? r : (r & 0x3) | 0x8; return v.toString(16); }); }At a glance, this appears to be a riff on common answers on Stack Overflow. I won't pick on this code for not using crypto.randomUUID, the browser function for doing this, as that function only started showing up in browsers in 2021. But using a format string and filling it with random data instead of generating your 128-bits as a Uint8Buffer is less forgivable.
This solution to generating UUIDs makes a common mistake: confusing the representation of the data with the reality of the data. A UUID is 128-bits of numerical data, with a few bits reserved for identification (annoyingly, how many bits are reserved depends on which format we're talking about). We render it as the dash-separated-hex-string, but it is not a dash-separated-hex-string.
In the end, this code does work. Awkwardly and inefficiently and with a high probability of collisions due to bad randomness, but it works. I just hate it.
[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!Fedora Amicably Resolves Legal Threat From OBS Studio Over Downstream Flatpak
Read more of this story at Slashdot.
Useless High-Voltage Power Lines Risk Sparking California Fires
Read more of this story at Slashdot.
Firefly's Moon-Orbiting 'Blue Ghost' Lunar Lander Tracked Earth-Orbiting GPS-Type Satellites
Read more of this story at Slashdot.
Animated 'Avatar: the Last Airbender' Gets Sequel, Plus Two More of Netflix's Live-Action Seasons
Read more of this story at Slashdot.
'Robot' Umpires Come to Major League Baseball (Spring Training) Games
Read more of this story at Slashdot.
Is the AI Boom Leading to More Natural Gas-Powered Utilities?
Read more of this story at Slashdot.
Richard Dawkins Asks ChatGPT If It's Conscious
Read more of this story at Slashdot.
Angry Workers Use AI to Bombard Businesses With Employment Lawsuits
Read more of this story at Slashdot.
Greg Kroah-Hartman Supports Rust in the Kernel
Read more of this story at Slashdot.
Mozilla Wants to Expand from Firefox to Open-Source AI and Privacy-Respecting Ads
Read more of this story at Slashdot.
Mozilla Wans to Expand from Firefox to Open-Source AI and Privacy-Respecting Ads
Read more of this story at Slashdot.
Elon Musk Urges Deorbiting the International Space Station 'As Soon as Possible'
Read more of this story at Slashdot.
Unexpected Shape of Lead-208 Nucleus May Force Scientists to Reevaluate Atomic Nuclei Models
Read more of this story at Slashdot.
Unexpected Shape of Lead-208 Nucleus of May Force Scientists to Reevaluate Atomic Nuclei Models
Read more of this story at Slashdot.
Amazon Is Killing the Ability to Download eBooks to Your Computer
Read more of this story at Slashdot.
Lithium Batteries Reignited Tuesday at the Moss Landing Power Plant Fire Site
Read more of this story at Slashdot.
AI May Not Impact Tech-Sector Employment, Projects US Department of Labor
Read more of this story at Slashdot.
Will Consumer Data Collection Lead to Algorithm-Adjusted 'Surveillance Pricing'?
Read more of this story at Slashdot.