public static int makeExpression(Common.FastRand rng, EvalSchema.Expression.Builder exp, int depth) { exp.SetOp(operations[rng.nextLessThan((short)EvalSchema.Operation.Modulus + 1)]); int left = 0; if (rng.nextLessThan(8) < depth) { int tmp = rng.nextLessThan(128) + 1; exp.GetLeft().SetValue(tmp); left = tmp; } else { left = makeExpression(rng, exp.GetLeft().InitExpression(), depth + 1); } int right = 0; if (rng.nextLessThan(8) < depth) { int tmp = rng.nextLessThan(128) + 1; exp.GetRight().SetValue(tmp); right = tmp; } else { right = makeExpression(rng, exp.GetRight().InitExpression(), depth + 1); } switch ((short)exp.GetOp()) { case 0: return(left + right); case 1: return(left - right); case 2: return(left * right); case 3: return(Common.div(left, right)); case 4: return(Common.modulus(left, right)); default: throw new System.Exception("impossible"); } }
public override int setupRequest(Common.FastRand rng, CatRankSchema.SearchResultList.Builder request) { int count = rng.nextLessThan(1000); int goodCount = 0; StructList.Builder <CatRankSchema.SearchResult.Builder> list = request.InitResults(count); for (int i = 0; i < list.Length; ++i) { CatRankSchema.SearchResult.Builder result = list.Get(i); result.SetScore(1000.0 - (double)i); int urlSize = rng.nextLessThan(100); int urlPrefixLength = URL_PREFIX.Length; Text.Builder url = result.InitUrl(urlSize + urlPrefixLength); java.nio.ByteBuffer bytes = url.asByteBuffer(); bytes.put(URL_PREFIX.asByteBuffer()); for (int j = 0; j < urlSize; j++) { bytes.put(unchecked ((byte)(97 + rng.nextLessThan(26)))); } bool isCat = rng.nextLessThan(8) == 0; bool isDog = rng.nextLessThan(8) == 0; if (isCat && !isDog) { goodCount += 1; } System.Text.StringBuilder snippet = new System.Text.StringBuilder(" "); int prefix = rng.nextLessThan(20); for (int j = 0; j < prefix; ++j) { snippet.Append(Common.WORDS[rng.nextLessThan(Common.WORDS.Length)]); } if (isCat) { snippet.Append("cat "); } if (isDog) { snippet.Append("dog "); } int suffix = rng.nextLessThan(20); for (int j = 0; j < suffix; ++j) { snippet.Append(Common.WORDS[rng.nextLessThan(Common.WORDS.Length)]); } result.SetSnippet(snippet.ToString()); } return(goodCount); }
public sealed override ulong setupRequest(Common.FastRand rng, CarSalesSchema.ParkingLot.Builder request) { ulong result = 0; StructList.Builder <CarSalesSchema.Car.Builder> cars = request.InitCars(rng.nextLessThan(200)); for (int i = 0; i < cars.Length; ++i) { CarSalesSchema.Car.Builder car = cars.Get(i); randomCar(rng, car); result += carValue(car.AsReader()); } return(result); }
internal static void randomCar(Common.FastRand rng, CarSalesSchema.Car.Builder car) { car.SetMake(MAKES[rng.nextLessThan(MAKES.Length)]); car.SetModel(MODELS[rng.nextLessThan(MODELS.Length)]); car.SetColor(colors[rng.nextLessThan((short)CarSalesSchema.Color.Silver + 1)]); car.SetSeats(unchecked ((byte)(2 + rng.nextLessThan(6)))); car.SetDoors(unchecked ((byte)(2 + rng.nextLessThan(3)))); foreach (CarSalesSchema.Wheel.Builder wheel in car.InitWheels(4)) { wheel.SetDiameter((ushort)(25 + rng.nextLessThan(15))); wheel.SetAirPressure((float)(30.0 + rng.nextDouble(20.0))); wheel.SetSnowTires(rng.nextLessThan(16) == 0); } car.SetLength((ushort)(170 + rng.nextLessThan(150))); car.SetWidth((ushort)(48 + rng.nextLessThan(36))); car.SetHeight((ushort)(54 + rng.nextLessThan(48))); car.SetWeight((uint)car.GetLength() * (uint)car.GetWidth() * (uint)car.GetHeight() / 200); CarSalesSchema.Engine.Builder engine = car.InitEngine(); engine.SetHorsepower((ushort)(100 * rng.nextLessThan(400))); engine.SetCylinders(unchecked ((byte)(4 + 2 * rng.nextLessThan(3)))); engine.SetCc((uint)(800 + rng.nextLessThan(10000))); engine.SetUsesGas(true); engine.SetUsesElectric(rng.nextLessThan(2) == 1); car.SetFuelCapacity((float)(10.0 + rng.nextDouble(30.0))); car.SetFuelLevel((float)(rng.nextDouble(car.GetFuelCapacity()))); car.SetHasPowerWindows(rng.nextLessThan(2) == 1); car.SetHasPowerSteering(rng.nextLessThan(2) == 1); car.SetHasCruiseControl(rng.nextLessThan(2) == 1); car.SetCupHolders(unchecked ((byte)rng.nextLessThan(12))); car.SetHasNavSystem(rng.nextLessThan(2) == 1); }