Computer Generated Randomness
I struggled to think of an idea for how to seed my random function. My first idea was to use MTA data on whether a train was late or not when I read that trains are ontime only 58% of the time which is almost like flipping a coin. However, I had trouble getting the data and I didn’t want to spend the majority of the time figuring out MTA’s api. I may use this for a future project. So I decided to implement psuedo-randomness using my local system time. I wanted to see how often and when it would feel like I’m cycling through the same values.
Part 1
See the Pen GxejYE by Jillian (@jzhong) on CodePen.
Above is a codepen with my function. The buttons let you get an example of what numbers would be generated depending on your needs. Below is the actual function that generates a number between 0 and 1.
function randomNum(){
var currentTime = new Date();
var currentHours = currentTime.getHours();
var currentMinutes = currentTime.getMinutes();
var currentSeconds = currentTime.getSeconds();
var currentMiliSeconds = currentTime.getMilliseconds();
var timeVal = currentHours * currentMinutes * currentSeconds * currentMiliSeconds;
var maxVal = 23 * 59 * 59 * 999;
var stringNum = String(timeVal / maxVal);
var editedNum = stringNum.slice(3,16);
var finalNum = Number(editedNum) / 1e13;
return finalNum;
}
Part 2
I decided to try using my custom random function to replace the javascript random() function in a bookmarklet I made for Hacking the Browser to see if I would perceive a difference in the behavior. Drag the link to your bookmarks bar and click it to start. Then click on any links on the browser page. After clicking a link, it should fly off in one of 8 directions that are randomly chosen.