浏览代码

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 年之前
父节点
当前提交
97a062e5dd
共有 1 个文件被更改,包括 8 次插入4 次删除
  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) {