/** * Get a random buyer UserId, where the probability that a particular user is selected increases * based on the number of bids that they have made in the past. We won't allow the last bidder to * be selected again * * @param previousBidders * @return */ public UserId getRandomBuyerId(Histogram<UserId> previousBidders, UserId... exclude) { // This is very inefficient, but it's probably good enough for now tmp_userIdHistogram.clear(); tmp_userIdHistogram.putHistogram(previousBidders); for (UserId ex : exclude) tmp_userIdHistogram.removeAll(ex); tmp_userIdHistogram.put(this.getRandomBuyerId(exclude)); try { LOG.trace("New Histogram:\n" + tmp_userIdHistogram); } catch (NullPointerException ex) { for (UserId user_id : tmp_userIdHistogram.values()) { System.err.println( String.format( "%s => NEW:%s / ORIG:%s", user_id, tmp_userIdHistogram.get(user_id), previousBidders.get(user_id))); } throw ex; } FlatHistogram<UserId> rand_h = new FlatHistogram<UserId>(rng, tmp_userIdHistogram); return (rand_h.nextValue()); }
public int getRandomCategoryId() { if (this.randomCategory == null) { this.randomCategory = new FlatHistogram<Integer>(this.rng, this.items_per_category); } return randomCategory.nextInt(); }