随机产生一个数字Java

public CustLib getRandomCustLib(User user, Customer customer){
GetCustLibImpl getCustLibImpl=new GetCustLibImpl();
List<CustLib> custLibs=getCustLibImpl.getCustLibs(user);
if(custLibs.size()<2){
Log.error("当前客户库数量为0或1,没有办法转移客户库");
return null;
}else {
CustLib custLibNow=new CustLib();
custLibNow.setId(customer.getLibId());
custLibNow.setTitle(customer.getLibName());
custLibs.remove(custLibNow);
     int num=(int)(Math.random()*(custLibs.size()));
CustLib custLibNext=new CustLib();
custLibNext.setId(custLibs.get(num).getId());
custLibNext.setTitle(custLibs.get(num).getTitle());
Log.info("随机获取的libId:"+custLibNext.getId());
Log.info("随机获取的libName:"+custLibNext.getTitle());
return custLibNext;
}
}
posted @ 2020-01-16 18:58  saifei1125  阅读(278)  评论(0编辑  收藏  举报