RSS | Archive | Random | E-mail

About

Hi, I'm Christian Castelli, a 28 years old italian programmer located in Pisa (Italy). Here I post small snippets of code which can be useful in my work.

Links

Codepuzzling main site
Development site
ByteStrike italian blog
Follow me on Twitter

My Life Style

while(passion) {
  try {
    myLife.run();
  }catch(LifeExceptions) {  
    stronger++;
    continue;
   }
}

Following

27 July 10

[JS] jQuery random number plugin

I’ve taken this little piece of code around the Web (sorry, I forgot the original source) and it’s a good example on how to develop a plugin for jQuery:

/** Usage:
* $.random(int);
* $.randomBetween(min, max); */
jQuery.extend({
	random: function(X) {
		return Math.floor(X * (Math.random() % 1));
	},
	randomBetween: function(MinV, MaxV) {
	  return MinV + jQuery.random(MaxV - MinV + 1);
	}
});

Comments (View)
  1. codepuzzling posted this
blog comments powered by Disqus
Themed by Hunson. Originally by Josh