/** * Return the last valid auction id (ignoring FIRST_AUCTION_ID). Will be the current auction id if * due to generate an auction. */ public static long lastBase0AuctionId(long eventId) { long epoch = eventId / GeneratorConfig.PROPORTION_DENOMINATOR; long offset = eventId % GeneratorConfig.PROPORTION_DENOMINATOR; if (offset < GeneratorConfig.PERSON_PROPORTION) { // About to generate a person. // Go back to the last auction in the last epoch. epoch--; offset = GeneratorConfig.AUCTION_PROPORTION - 1; } else if (offset >= GeneratorConfig.PERSON_PROPORTION + GeneratorConfig.AUCTION_PROPORTION) { // About to generate a bid. // Go back to the last auction generated in this epoch. offset = GeneratorConfig.AUCTION_PROPORTION - 1; } else { // About to generate an auction. offset -= GeneratorConfig.PERSON_PROPORTION; } return epoch * GeneratorConfig.AUCTION_PROPORTION + offset; } /** * Return a random auction id (base 0). */ public static long nextBase0AuctionId( long nextEventId, Random random, GeneratorConfig config) { // Choose a random auction for any of those which are likely to still be in flight, // plus a few 'leads'. // Note that ideally we'd track non-expired auctions exactly, but that state // is difficult to split. long minAuction = Math.max( lastBase0AuctionId(nextEventId) - config.getNumInFlightAuctions(), 0); long maxAuction = lastBase0AuctionId(nextEventId); return minAuction + nextLong(random, maxAuction - minAuction + 1 + AUCTION_ID_LEAD); }