Skip to content

Instantly share code, notes, and snippets.

@davidfowl
Created April 26, 2013 04:52
Show Gist options
  • Select an option

  • Save davidfowl/5465096 to your computer and use it in GitHub Desktop.

Select an option

Save davidfowl/5465096 to your computer and use it in GitHub Desktop.
function addUser(name, room, active, owner) {
var user = {
name: name,
hash: null,
owner: owner,
active: active,
noteClass: '',
note: 'This is a note',
flagClass: '',
flag: 'bb',
country: 'Barbados',
lastActive: new Date(),
timeAgo: $.timeago(new Date()),
admin: false
};
window.chat.ui.addUser(user, room);
}
function removeUser(name, room) {
window.chat.ui.removeUser({Name: name}, room)
}
function isOwner(n) {
return n < 3;
}
function isActive(n) {
return getRandomInt(0, n) > (n/2);
}
function randomActivity(maxUsers, room)
{
var index = getRandomInt(0, maxUsers);
if(getRandomInt(0, 1) === 1) {
addUser("user_" + index, room, isActive(index), isOwner(index), room);
}
else {
removeUser("user_" + index, room);
}
var nextInterval = Math.round(Math.random() * (1000 - 500)) + 500;
setTimeout(function() {
randomActivity(maxUsers, room);
},
nextInterval);
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
randomActivity(300, "newRoom")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment