Generating Random Whole numbers in JavaScript in a specific range Sh Raj on January 14, 2022 Video Documentation :- https://youtu.be/xz3VbIaEG8o Mozilla Developer Network page on this JavaScript Math Object: https://developer.mozil... Read full post Submit Preview Dismiss Collapse Expand Jon Randy ποΈ Jon Randy ποΈ Jon Randy ποΈ Follow π€ Artisanal developer - coding with varying degrees of success since 1983 Location Bangkok πΉπ Joined Jun 1, 2018 • Jan 14 '22 Dropdown menu Copy link Hide About 40% faster: const getRandomInt = (min, max)=>~~(Math.random()*(max-min+1)+min) Enter fullscreen mode Exit fullscreen mode Collapse Expand πWii π³οΈββ§οΈ πWii π³οΈββ§οΈ πWii π³οΈββ§οΈ Follow Blog: https://blog.but.gay Mastodon: @darkwiiplayer@tech.lgbt Pronouns: en.pronouns.page/@darkwiiplayer Pronouns she/her;q=1, they/them;q=0.8, */*;q=0.2 Joined Dec 4, 2018 • Jan 14 '22 Dropdown menu Copy link Hide It's faster because it doesn't work; at least not for numbers bigger than what fits in a 32-bit integer ;) Collapse Expand Jon Randy ποΈ Jon Randy ποΈ Jon Randy ποΈ Follow π€ Artisanal developer - coding with varying degrees of success since 1983 Location Bangkok πΉπ Joined Jun 1, 2018 • Jan 14 '22 Dropdown menu Copy link Hide Poorly written spec ;) πWii π³οΈββ§οΈ πWii π³οΈββ§οΈ πWii π³οΈββ§οΈ Follow Blog: https://blog.but.gay Mastodon: @darkwiiplayer@tech.lgbt Pronouns: en.pronouns.page/@darkwiiplayer Pronouns she/her;q=1, they/them;q=0.8, */*;q=0.2 Joined Dec 4, 2018 • Jan 14 '22 Dropdown menu Copy link Hide The spec is wrong π Collapse Expand Sh Raj Sh Raj Sh Raj Follow IamSh - 45K+ Followers on dev.to/sh20raj Location ππ INDIAππ Joined Jan 9, 2022 • Jan 14 '22 Dropdown menu Copy link Hide Can You Minify this Function also... function getParameterByName( name ){ name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results == null ) return ""; else return decodeURIComponent(results[1].replace(/\+/g, " ")); } Enter fullscreen mode Exit fullscreen mode Collapse Expand πWii π³οΈββ§οΈ πWii π³οΈββ§οΈ πWii π³οΈββ§οΈ Follow Blog: https://blog.but.gay Mastodon: @darkwiiplayer@tech.lgbt Pronouns: en.pronouns.page/@darkwiiplayer Pronouns she/her;q=1, they/them;q=0.8, */*;q=0.2 Joined Dec 4, 2018 • Jan 14 '22 • Edited on Jan 14 • Edited Dropdown menu Copy link Hide No need, your browser already minified it for you and put it in a class called URLSearchParams π Collapse Expand codingjlu codingjlu codingjlu Follow Joined Jun 15, 2021 • Jan 17 '22 Dropdown menu Copy link Hide The "minified" form doesn't behave the same. In negative numbers, the first function is inclusive, while the second one is exclusive. Run both about 30 times to see what I mean, and pass the values -10, -1. Code of Conduct • Report abuse
About 40% faster:
It's faster because it doesn't work; at least not for numbers bigger than what fits in a 32-bit integer ;)
Poorly written spec ;)
The spec is wrong π
Can You Minify this Function also...
No need, your browser already minified it for you and put it in a class called
URLSearchParamsπThe "minified" form doesn't behave the same. In negative numbers, the first function is inclusive, while the second one is exclusive.
Run both about 30 times to see what I mean, and pass the values
-10, -1.