方法一(其实是毫秒时间数字字符串):

  1. function randomString() {
  2. return '' + new Date().getTime();
  3. }

  方法二(随机字母数字字符串):

    1. var alpha_num_chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
    2. function randomString(length) {
    3. if (! length) {
    4. length = Math.floor(Math.random() * alpha_num_chars.length);
    5. }
    6. var str = '';
    7. for (var i = 0; i < length; i++) {
    8. str += alpha_num_chars[Math.floor(Math.random() * alpha_num_chars.length)];
    9. }
    10. return str;
    11. }
    12. // generate a random string of random length
    13. randomString();
    14. // generate a random string of length 8
    15. randomString(8);

使用Javascript实现随机字符串的更多相关文章

  1. JS生成随机字符串的多种方法

    这篇文章主要介绍了JS生成随机字符串的方法,需要的朋友可以参考下 下面的一段代码,整理电脑时,记录备查. <script language="javascript"> ...

  2. JavaScript 编写随机四位数验证码(大小写字母和数字)

    1.JavaScript编写随机四位数验证码,用到的知识点为: a.Math对象的随机数:Math.random() b.Math对象的取整    :Math.floor() c.处理所需要的下标个数 ...

  3. 【转】有关Oracle随机字符串的生成方法及具体应用

    Oracle生成随机字符串的方法是通过dbms_random.string实现的. 1.dbms_random.string用法Oracle官方文档参考链接:http://download.oracl ...

  4. [源码]RandomId 生成随机字符串

    /* * 名称:RandomId * 功能:生成随机ID * 作者:冰麟轻武 * 日期:2012年1月31日 03:36:28 * 版本:1.0 * 最后更新:2012年1月31日 03:36:28 ...

  5. .net生成随机字符串

    生成随机字符串的工具类: /// <summary> /// 随机字符串工具类 /// </summary> public class RandomTools { /// &l ...

  6. PHP 生成随机字符串与唯一字符串

    说明:生成随机字符串用到的方法有 mt_rand() 生成唯一字符串用到的方法有 md5(),uniqid(),microtime() 代码: <?php /* * 生成随机字符串 * @par ...

  7. PHP学习笔记:万能随机字符串生成函数(已经封装好)

    做验证码用到的,然后就把这个函数封装起来,使用时候要设置2个参数: $str设置里要被采集的字符串,比如: $str='efasfgzsrhftjxjxjhsrth'; 则在函数里面生成的字符串就回从 ...

  8. shell 生成指定范围随机数与随机字符串 .

    shell 生成指定范围随机数与随机字符串         分类:             shell              2014-04-22 22:17     20902人阅读     评 ...

  9. random and password 在Linux下生成crypt加密密码的方法,shell 生成指定范围随机数与随机字符串

    openssl rand -hex n (n is number of characters) LANG=c < /dev/urandom tr -dc _A-Z-a-z-0-9 | head ...

随机推荐

  1. linux下停止tomcat

    bin/shutdown.sh -force 强行停掉tomcat 重启tomcat的脚本: /home/tomcat/bin/shutdown.sh -force/home/tomcat/bin/s ...

  2. git config 的全局配置

    使用git的全局配置   .gitconfig 一:修改 用户下的.gitconfig 修改如图信息,添加你的信息 二: 命令添加 $ git config --global user.name   ...

  3. git fatal: https://github.com/TeaCodie/TeaCodie-Website.git/info/refs not found: did you run git update-server-info on the server 错误

    错误: fatal: https://github.com/TeaCodie/TeaCodie-Website.git/info/refs not found: did you run git upd ...

  4. Struts完美解决i18n问题

    所谓的i18n问题指的是(软件的)国际化问题,简单来讲就是使我们的软件可以让世界使用任何语言的人们都能使用,软件自身会根据语言环境的不同进行自动配置,如果你是中文环境那界面以中文显示,如果是英文环境就 ...

  5. codechef The Ball And Cups题解

    The Ball And Cups At the end of a busy day, The Chef and his assistants play a game together. The ga ...

  6. taro 打包微信小程序运行失败(二)

    1.报错信息 thirdScriptError sdk uncaught third Error Cannot read property 'dispatch' of null TypeError: ...

  7. GNU C中的零长度数组

    http://blog.csdn.net/ssdsafsdsd/article/details/8234736 在标准C和C++中,长度为0的数组是被禁止使用的.不过在GNU C中,存在一个非常奇怪的 ...

  8. 〖C++〗string2int把字符串转换成int的函数

    #include <stdio.h> #include <stdlib.h> #include <string.h> int string2int(char *ar ...

  9. java web 解决Form表单乱码问题

    JSP和Servlet的六种中文乱码处理方法 一.表单提交时出现乱码: 在进行表单提交的时候,经常提交一些中文,自然就避免不了出现中文乱码的情况,对于表单来说有两种提交方式:get和post提交方式. ...

  10. mosquitto $SYS下topic

    $SYS/broker/clients/connected