Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "math.random"
-
So the person from my previous rant actually tried to make AI in HTML.
Person: I made that AI in HTML today!
Me: Oh really?
Person: Yup. *Opens HTML site*
It was a site that
1) Used JavaScript
2) Was a prompt(), and after answering it alerts "Yes" or "No" randomly.
Me: That's not AI
Person: Uhh yeah it is. It uses a neural network to answer!
Me: Actually, a neural network is a dot product of an input and vectors that are refined using partial derivatives.
Person: Yeah! That's what Math.random() and alert() do!
I left that room as quickly as I could (yet again).30 -
Most hated language features?
PL/SQL:
• it exists
XSLT:
• it also exists
PHP:
• it still exists.
VB:
• Significant parentheses: `subName` calls the subroutine, and `subName()` calls the subroutine and gets a return value. If you use the wrong invocation, it yells at you. Why!?
• For reasons unknown, you can only have `sleep` appear once per codebase. (So put it in a function!)
Ruby:
• It’s bloody easy to write code with absolute shit performance, and it kind of feels encouraged because of just how easy Ruby makes everything. Less critical thinking means worse performance, and Ruby’s blissful elegance encourages mental laziness.
• Minor: You cannot pass a hash as the first method parameter without enclosing it in parentheses, ex:`method({key: value})`. This is due to the ambiguous case between passing a hash argument and a (curly) block/proc (`method {|args| code}`). This could be remedied pretty easily with a little bit of look ahead.
• Minor: There is no `elsif` for `unless` (a negated if). Why? No reason given.
Python:
• no block endings, so nested code can be extremely difficult to follow.
Bash:
• The freaking syntax oh god why.
All languages:
• rand vs rand() vs Rand vs Rand() vs rnd vs RND vs random() vs random vs randInt() vs Math.random() vs Math.randInt() vs ...18 -
this.onSleep = function() {
for(let i = 0; i < hair.length; i++) {
hair[i].orientation = Math.random();
}
Object.freeze(hair);
}
😐
Whoever thought it was a good idea to put this there, fuck you.15 -
Date.prototype.valueOf = Math.random;
Use this as your 1st line of code in any web page or node server, for maximum lulz.9 -
Expectation: rants.sort((rantA, rantB) => rantA.votes - rantB.votes);
Reality: rants.sort((rantA, rantB) => (rantA.votes - 0.5) + Math.random());
What??1 -
Happy age++ for me!
or age += 1
or age - age + age + 1
or while (newAge !== age +1) newAge = Math.random(0, 100)3 -
function getUnstuck(){
var methods = [
"getting on devRant for a bit",
"adding new functionality to your program",
"refactoring a function or two",
"working on a personal project for a bit",
"zoning out on some music to clear your thoughts",
"getting up from your desk and going to talk to someone",
"getting more coffee",
"taking a \"lunch\" break at the bar",
"just fucking leaving for the day"
];
return "try " + methods[parseInt(Math.random() * methods.length)];
} -
I wrote an auth today.
Without frameworks. Without dependencies. Without under-the-hood magic. Without abstract pluggable adaptor modules for the third-party auth library with 63 vulnerabilities and 1252 GitHub issues. Without security vulnerabilities showing up in NPM log. Without dependency of a dependency of a dependency using md5 and Math.random() under the hood for historical reasons, and now we're fucked, because this is the only lib for our framework, and we have no time to write our own replacement. Without all that shit.
Rock-solid, on top of scrypt. Stateless and efficient.
It felt amazing.9 -
var dayInMyLife = function(data) {
var checkDevRant = setInterval(function() { openDevRant(); }, Math.random()*10000),
workday = (data.day.toLowerCase() == 'saturday' || data.day.toLowerCase() == 'sunday' || data.holiday == true) ? false : true;
if (workday) {
var schedule = {
'wakeup': '06:45',
'travelToWork': {
'time': '07:10',
'method': 'walking'
},
'lunch': '11.00',
'travelToHome': {
'time': '15:30',
'method': 'walking'
}
};
while (atWork) {
keepZeroInbox();
beAmongDinosaurs();
if (checkForProjects()) {
doProject();
};
while (noisyCoworkers) {
useNoiseCancellationHeadset();
};
};
spendPreciousFreeTimeWithFamily();
enterSleepMode();
}
}
var today = dayInMyLife({'day': 'monday', 'holiday': false});1 -
Code for Matrix Rain Using HTML
<!DOCTYPE html>
<html>
<head>
<title>Matrix Rain</title>
<style>
* {margin: 0; padding: 0;}
body {background: black;}
canvas {display: block;}
</style>
</head>
<body>
<canvas id="c"></canvas>
</body>
<script>
var c = document.getElementById("c");
var ctx = c.getContext("2d");
//making the canvas full screen
c.height = window.innerHeight;
c.width = window.innerWidth;
//english characters
var english = "1001010101110101010101010010101000101011101111010101010110101010101010101110000101";
//converting the string into an array of single characters
english = english.split("");
var font_size = 15;
var columns = c.width/font_size; //number of columns for the rain
//an array of drops - one per column
var drops = [];
//x below is the x coordinate
//1 = y co-ordinate of the drop(same for every drop initially)
for(var x = 0; x < columns; x++)
drops[x] = 1;
//drawing the characters
function draw()
{
//Black BG for the canvas
//translucent BG to show trail
ctx.fillStyle = "rgba(0, 0, 0, 0.05)";
ctx.fillRect(0, 0, c.width, c.height);
ctx.fillStyle = "#0F0"; //green text
ctx.font = font_size + "px arial";
//looping over drops
for(var i = 0; i < drops.length; i++)
{
//a random chinese character to print
var text = english[Math.floor(Math.random()*english.length)];
//x = i*font_size, y = value of drops[i]*font_size
ctx.fillText(text, i*font_size, drops[i]*font_size);
//sending the drop back to the top randomly after it has crossed the screen
//adding a randomness to the reset to make the drops scattered on the Y axis
if(drops[i]*font_size > c.height && Math.random() > 0.975)
drops[i] = 0;
//incrementing Y coordinate
drops[i]++;
}
}
setInterval(draw, 33);
</script>
<body>
</html>1 -
Every team building event, the company run a random draw to organise the teams.
It looks like the random equations not applicable to the beauty lady and the rich guy, they always match together.
What a draw...
Should I give them actual simple running draw app! Or they may hate me :) -
This will never clash:
static createGuid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + s4() + s4(); // Example => 'e014026082e6237b'
} -
How the fuck are lifts programmed? Two lifts in a shaft, one at level 0, the other at level 4, I call it from level -1. Which one comes? You bet your ass it's the one from lvl 4. Is it Math.random()?6