Java 模板权重随机
2015-09-09 09:55
471 查看
Template templates=...// 所有的模板 final int _weights=1000; // 所有的模板权重 Template _template=null; //随机一个权重 int rand = RandomUtil.nextInt(0, _weights); int lastEd = 0; int curEd = 0; // 根据随机的权重找到对应的模板 for(Template _templ : templates) { int eden = _templ .getWeight(); curEd += eden; if(lastEd <= rand && rand < curEd){ _template=_templ; break; } lastEd += eden; }
相关文章推荐
- 学习日志---图之最小生成树算法
- 如何取消eclipse设置项目的默认路径
- Java NIO -- FileChannel
- Jboss7使用指定jdk
- Eclipse 连接MySQl数据库总结
- 三分钟理解Java中字符串(String)的存储和赋值原理
- Java回调机制解析
- Eclipse中文字体调整
- Java第三周-根据类关系图实现抽象类,接口,子类
- 关于用eclipse查看jar包中源码的解决办法
- Java中List迭代过程中删除、新增元素的处理
- Java常见报错解决办法
- ubuntu修改java安全性
- Java第三周-Double与String类型变量相互转换
- Java第三周-数的比较与绝对值的计算
- java.util.ConcurrentModificationException
- 【Java EE 学习 35 下】【struts2】【struts2文件上传】【struts2自定义拦截器】【struts2手动验证】
- java jstack dump 线程 介绍 解释
- Spring学习笔记(九):Spring拦截器和java过滤器的区别
- Eclipse使用小技巧——备忘