Browse Source

support calling rand without arguments.

which is shorter than Math.random() and more consistent if rand is used
in the same places.
Lucas Stadler 12 years ago
parent
commit
97a062e5dd
1 changed files with 8 additions and 4 deletions
  1. 8 4
      js/pixl/public/trixl.html

+ 8 - 4
js/pixl/public/trixl.html

@ -109,10 +109,14 @@
109 109
		}
110 110
111 111
		var rand = function(lo, hi) {
112
			var both = hi !== undefined,
113
			    l = both ? lo : 0,
114
			    h = both ? hi : lo;
115
			return l + Math.round(Math.random() * (h - l));
112
			switch (arguments.length) {
113
			case 0:
114
				return Math.random();
115
			case 1:
116
				return Math.round(Math.random() * lo);
117
			default:
118
				return lo + Math.round(Math.random() * (hi - lo));
119
			}
116 120
		}
117 121
118 122
		var rgbFromCss = function(color) {