`
coconut_zhang
  • 浏览: 533997 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

随机生成时间

    博客分类:
  • java
 
阅读更多
private Color getRandColor(int fc, int bc) { // 给定范围获得随机颜色  
     Random random = new Random();  
    if (fc > 255)  
       fc = 255;  
    if (bc > 255)  
       bc = 255;  
    int r = fc + random.nextInt(bc - fc);  
    int g = fc + random.nextInt(bc - fc);  
    int b = fc + random.nextInt(bc - fc);  
    return new Color(r, g, b);  
   }

    getRandColor(200, 250)



随机生成时间:
Random   rand   =   new   Random();
SimpleDateFormat   format   =   new   SimpleDateFormat( "yyyy-MM-dd ");
Calendar   cal   =   Calendar.getInstance();
cal.set(1900,   0,   1);
long   start   =   cal.getTimeInMillis();
cal.set(2008,   0,   1);
long   end   =   cal.getTimeInMillis();
for(int   i   =   0;   i   <   10;   i++)   {
Date   d   =   new   Date(start   +   (long)(rand.nextDouble()   *   (end   -   start)));
System.out.println(format.format(d));
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics