I don't know much about Javascript, and this function I wrote doesn't seem to be working properly. I don't know where it is going wrong, just that sometimes it doesn't work properly.
Any advice on how to improve it?
function GetRandomLoadingMessage()
{
var d = new Date();
var weekday = d.getDay();
var month = d.getMonth();
var seed = weekday + "" + year;
var choice = Math.round(Math.random(seed) * 2);
if (choice == 1) {
var lines = new Array(
"Pay no attention to the man behind the curtain",
"Follow the white rabbit",
"The satellite is moving into position",
"You're not in Kansas anymore",
"Reticulating Splines",
"The gods conemplate your fate",
"It's not you, it's me",
"So, do you come here often?",
"Counting backwards from infinity",
"Rolling for initiative");
}
if (choice == 2) {
var lines = new Array(
"E.T. phone home",
"May the force be with you",
"Here's looking at you, kid",
"I'm gonna make him an offer he can't refuse",
"Bond. James Bond.",
"You're gonna need a bigger boat",
"I'll be back",
"Soylent Green is people!",
"Open the pod bay doors, HAL",
"Shaken, not stirred");
}
if (choice == 3) {
var lines = new Array(
"Parallel processors running perpendicular today",
"Interference from lunar radiation",
"Positron routers depleted",
"Borg nanites infesting the server",
"Astropneumatic oscillations inducing delays",
"Increased sunspot activity",
"Packets were eaten by the terminator",
"Network packets travelling uphill",
"Trojan horse ran out of hay",
"Change in the earth's rotational speed");
}
return lines[Math.round(Math.random()*(lines.length-1))];
}
The idea, as you may have guessed, is to display messages from one particular "section" each day, at random... hence using a seed. Although I should change Year to Month or something.
Edit: Ok! Thanks for the information. I really need to figure out how to have a SEED though, like in C#. Is there a way? Each day I want it to choose a list and give responses from that list. By seeding from a combination of day/month, I could always use the same list for a given day.