各位朋友对" JavaScript挑战赛--随机颜色"的挑战代码

当天,也就是6月3日,我很高兴收到了来自江、的代码(QQ: 676596050,Blog:http://hi.baidu.com/jiang_yy_jiang )的代码。

在他博客中的原始代码见 http://hi.baidu.com/jiang_yy_jiang/blog/item/1494c5b3a961b5add8335a72.html

对于他的代码,我整理如下:


/******
 * name: 江、
 * qq: 676596050
 * blog: http://hi.baidu.com/jiang_yy_jiang
 */
function GetColor(){
    var str = "0123456789abcdef", t = "";
    for (j = 0; j < 6; j++) {
        t = t + str.charAt(Math.random() * str.length);
    }
    return t;
}

 

 

 

一旦有新的代码,我将列出来,供各位javascript爱好者讨论,切磋,并评比



/ * ***
         * name:shelly→水
         * QQ:49812643
         */
        function randomColor(){
            return "rgb(" + Math.round(Math.random() * 256) + "," + Math.round(Math.random() * 256) + "," + Math.round(Math.random() * 256) + ")";
        }

 


 

 

 

/****
         * name:我佛山人
         * qq:52739105
         * blog:
         */
        function randomColor_foshan(){
            return ((new Date()).getTime().toString(16).substr(-6));
           
        }

 

 

 

 

 

/****
         * name:匿名
         * qq:
         * blog:
         */
        function randomColor(){
            return 'rgb(' + [Math.random() * 256 | 0, Math.random() * 256 | 0, Math.random() * 256 | 0].join(',') + ')';
        }

 

 

 

 


 

 

/****
         * name:角蝰er
         * qq:16198008
         * blog:http://www.zerolone.com
         */
        function randomColor_zerolone(){
            return Math.random().toString(16).substring(2, 8);
        }

/*本人(FuDesign2008@163.com)经过测试,randomColor_zerolone 比我的函数要优秀,除了在WindosXP+FF的环境下;基于角蝰er的代码简洁,清晰,易读,在性能上更好,且是第一个,因此本人决定送出一本《jjavascript:The Definitive Guide》。因为角蝰er更喜欢中文版,所以送出中文版的。*/

 

/*基于治方(zm)(QQ:15586293)的道理,本人先暂停(只是暂停)书籍的送出,待资料查证确认后,再做决定。*/

由于我个人的疏忽和技术水平,向给我javascript爱好者致歉;尤其是角蝰er网友,为了保持公正和追求技术的完美,我不能送出书籍,非常非常抱歉!!!

治方(zm)(QQ:15586293)说的是正确的,在javascript中Math.random()的值域是[0,1)。参考资料见 http://objjob.phrogz.net/js/method/732

 

 

 



/****
     * name:我佛山人
     * qq:52739105
     * blog:
     */
    function randomColor_foshan_2(){
        return (new Date().getTime() & 0xffffff).toString(16);
    }

 

 

    
    /****
     * name:治方(zm)15586293
     * qq:15586293
     * blog:
     */
    function randomColor_zm(){
        var color = Math.round(Math.random() * 0xffffff).toString(16);
        (color == 0) && (color = "000000");
        return color;
    }



/****
     * name:角蝰er
     * qq:16198008
     * blog:http://www.zerolone.com
     */
    function randomColor_zerolone_2(){
        return (Math.random()+0.00000001).toString(16).substring(2, 8);
    }

 

 

    /****
     * name:我佛山人
     * qq:52739105
     * blog:
     */
    function randomColor_foshan_3(){
        var v = (new Date() & 0xffffff).toString(16), l = v.length;
        return l < 6 && (['00000','0000','000','00','0'][l - 1] + v) : v;
    }


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值