private double UniformLuck() { double newLuckValue = RandGen.Next(-100, 101) / 1000.0; // The range is [-100, 101) (inclusive left, exclusive right) Monitor.Log($"Uniform NewLuck: {newLuckValue}", LogLevel.Trace); return(newLuckValue); }
private string GenerateMaleFirstName() { var index = RandGen.Next(0, _maleFirstNames.Count); Sex = Gender.Male; return(_maleFirstNames.AsEnumerable().ElementAt(index)); }
/*public override void Mitosis(int n) * { * // mitosis is the process of cell division resulting in two (here n) * // daughter cells which are identical to the original nucleus * for (int i = 0; i < n; i++) * { * // TODO: Hard coded line * var mutatedPattern = GetMutatedPattern(50, true); * var newCell = new HelperTCell(Parent, mutatedPattern); * //Parent.AddCell(newCell); * } * Apoptosis(); * }*/ protected override void OnLifeEnd() { // TODO: MODIFICATION FOR HYPERMUTATION if (ExtraLifespan > 0 && RandGen.Next(0, 3) == 1) { Mitosis(1); } base.OnLifeEnd(); }
/// <summary> /// Gets the random city, state, zip line from the resource file /// </summary> private void GetRandomCityStateZip() { if (_citystatezip == null) { _citystatezip = ReadResourceByLine(CityFile); } var index = RandGen.Next(0, _citystatezip.Count); cityStateZipLine = _citystatezip.AsEnumerable().ElementAt(index); }
internal void SanityCheck() { sb.Clear() .Append("Sanity Test: Five random numbers: "); for (int i = 0; i < 5; i++) { sb.Append(RandGen.Next().ToString()) .Append(" "); } this.Monitor.Log(sb.ToString(), LogLevel.Debug); }
/// <summary> /// Sends a cell to a randomly-selected type-specific tissue. /// </summary> /// <param name="cell">The cell to be sent to another tissue.</param> /// <param name="tissueType">The type of destination tissue.</param> protected void SendCellToRandomTissue(Cell cell, TissueType tissueType) { var typeAddresses = from address in addressList where (address.Value == tissueType) select address.Key; var typeCount = typeAddresses.Count(); if (typeCount > 0) { int randIx = RandGen.Next(0, typeCount); SendCell(cell, typeAddresses.ElementAt(randIx)); } }
private void getValidRandomFirstTile(GameBoard i_Board, out int o_Row, out int o_Col) { int randRow = RandGen.Next(k_MinValue, i_Board.r_Rows); int randCol = RandGen.Next(k_MinValue, i_Board.r_Cols); while (i_Board.m_State[randRow, randCol] == eCellState.Open) { randRow = RandGen.Next(k_MinValue, i_Board.r_Rows); randCol = RandGen.Next(k_MinValue, i_Board.r_Cols); } o_Row = randRow; o_Col = randCol; }
/// <summary> /// Create service instances. /// </summary> /// <param name="instances">Create and initialize the service instances</param> /// <param name="isRandomNumberOfPartitions">True if random number of Partitions (less than or equal to max number of partitions) per instance, false initialize max number of partitions</param> /// <param name="numOfPartitionsPerInstance">Number of partitions per instance</param> static void InitializeInstances(InstanceRecord[] instances, bool isRandomNumberOfPartitions, int numOfPartitionsPerInstance) { for (int instanceIndex = 0; instanceIndex < instances.Count(); instanceIndex++) { Uri instanceName = new Uri("fabric:/test/svcInstance/" + instanceIndex); // Initialize partitions int partitionCount = numOfPartitionsPerInstance; if (isRandomNumberOfPartitions) { partitionCount = RandGen.Next(1, numOfPartitionsPerInstance); } instances[instanceIndex] = new InstanceRecord(instanceName, partitionCount); } }
private void ForwardSignal(Signal signal) { // determine the appropriate number of receiver cells int receiverCellsCount; var aliveCells = Agents.Where(cell => cell.IsAlive); var aliveCellsCount = aliveCells.Count(); if (aliveCellsCount > 0) { if (signal is SecretiveSignal) { // secretive signals are propagated based on their concentrations var secretiveSignal = signal as SecretiveSignal; receiverCellsCount = (int)Math.Ceiling( ((double)secretiveSignal.Concentration / Globals.FullDispatchConcentrationThreshold) * aliveCellsCount); if (receiverCellsCount > aliveCellsCount) { receiverCellsCount = aliveCellsCount; } } else { // non-secretive signals are propagated in a constant rate receiverCellsCount = (int)Math.Ceiling(0.5 * aliveCellsCount); // TODO: X64 } // choose some random indices var randomIndices = new List <int>(); while (randomIndices.Count < receiverCellsCount) { int ix = RandGen.Next(0, aliveCellsCount); if (!randomIndices.Contains(ix)) { randomIndices.Add(ix); } } foreach (int randIX in randomIndices) { // stimulate the cell // TODO: the signal dispatch delay is dummy Scheduler.Schedule(aliveCells.ElementAt(randIX).HandleSignal, 0.0001, signal); } } }
private static string Sentenceify(IEnumerable <string> words) { var text = new StringBuilder(); var wordCount = words.Count(); var handledWords = 0; while (handledWords < wordCount) { var length = RandGen.Next(5, 10); var sentence = string.Join(" ", words.Skip(handledWords).Take(length)); sentence = Regex.Replace(sentence, @"^\w", match => match.Value.ToUpper()); text.AppendFormat("{0}. ", sentence); handledWords += length; } return(text.ToString()); }
public Point ChooseSecondTile(GameBoard i_Board) { int firstTile = int.MaxValue; bool foundFirstTile = false; Point firstTileOpened = new Point(); Point tileOpened = new Point(); for (int i = 0; i < i_Board.r_Rows && foundFirstTile == false; i++) { for (int j = 0; j < i_Board.r_Cols && foundFirstTile == false; j++) { if (i_Board.m_State[i, j] == eCellState.TurnOpen) { firstTile = i_Board.m_Board[i, j]; firstTileOpened.X = i; firstTileOpened.Y = j; } } } if (RandGen.Next(k_MinValue, k_MaxValue) < k_Difficulty && m_CountRevealed[firstTile] == k_MaxCountRevealed) { for (int i = 0; i < i_Board.r_Rows; i++) { for (int j = 0; j < i_Board.r_Cols; j++) { if (i_Board.m_Board[i, j] == firstTile && (firstTileOpened.X != i || firstTileOpened.Y != j)) { i_Board.m_State[i, j] = eCellState.TurnOpen; tileOpened.X = i; tileOpened.Y = j; } } } } else { getValidRandomSecondTile(i_Board, out int o_RandRow, out int o_RandCol); i_Board.m_State[o_RandRow, o_RandCol] = eCellState.TurnOpen; tileOpened.X = o_RandRow; tileOpened.Y = o_RandCol; } return(tileOpened); }
public void hit() { if (Game.Player.Character.IsInRangeOf(start, 3f) && !_isStarted) { UI.Notify("Picked up package"); _isStarted = true; blip?.Remove(); blip = World.CreateBlip(end); blip.Color = BlipColor.Red; } if (Game.Player.Character.IsInRangeOf(end, 3f) && _isStarted) { _isStarted = false; UI.Notify("Finished!"); Game.Player.Money += RandGen.Next(2, 5); blip.Remove(); isActive = false; } }
// the following method assembles a sensory input vector for the cognitive array public double[][] makeRandomInputVector() { // creating an input vector for all leaves // 12 inputs for limbs, 5 for IRs and Mics, 64 for the 8 line frame metanodes double[][] inputVector = new double[10][]; // **************** Adding Limb sensor data ******************* inputVector[0] = new double[12]; inputVector[0][0] = RandGen.Next(2); inputVector[0][1] = RandGen.Next(2); inputVector[0][2] = RandGen.Next(2); inputVector[0][3] = RandGen.Next(2); inputVector[0][4] = RandGen.Next(2); inputVector[0][5] = RandGen.Next(2); inputVector[0][6] = RandGen.Next(2); inputVector[0][7] = RandGen.Next(2); inputVector[0][8] = RandGen.Next(3); inputVector[0][9] = RandGen.Next(3); // normalizing the shoulder pots to a 0-3 scale inputVector[0][10] = (RandGen.Next(1023) * 4) / 1023; inputVector[0][11] = (RandGen.Next(1023) * 4) / 1023; // ******************** Done with Limbs sensors ******************** // ******************************** Adding mics and IRs ************** inputVector[1] = new double[5]; inputVector[1][0] = RandGen.Next(1023) * 4 / 1023; inputVector[1][1] = RandGen.Next(1023) * 4 / 1023; inputVector[1][2] = RandGen.Next(1023) * 4 / 1023; inputVector[1][3] = RandGen.Next(1023) * 4 / 1023; inputVector[1][4] = RandGen.Next(1023) * 4 / 1023; // ********************** Adding the thresholded frame lines ********** // threholding first... byte[] threshImage = new byte[ABSTRACTION_FRAME_HEIGHT * ABSTRACTION_FRAME_WIDTH]; int i; for (i = 0; i < ABSTRACTION_FRAME_WIDTH * ABSTRACTION_FRAME_HEIGHT; i++) { threshImage[i] = (RandGen.Next(101) < 50) ? (byte)0 : (byte)1; } // Line 1 inputVector[2] = new double[8]; for (i = 0; i < 8; i++) { inputVector[2][i] = threshImage[i]; } // Line 2 inputVector[3] = new double[8]; i = 0; for (i = 0; i < 8; i++) { inputVector[3][i] = threshImage[8 + i]; } // Line 3 inputVector[4] = new double[8]; i = 0; for (i = 0; i < 8; i++) { inputVector[4][i] = threshImage[16 + i]; } i = 0; // Line 4 inputVector[5] = new double[8]; for (i = 0; i < 8; i++) { inputVector[5][i] = threshImage[24 + i]; } // Line 5 inputVector[6] = new double[8]; for (i = 0; i < 8; i++) { inputVector[6][i] = threshImage[32 + i]; } // Line 6 inputVector[7] = new double[8]; for (i = 0; i < 8; i++) { inputVector[7][i] = threshImage[40 + i]; } // Line 7 inputVector[8] = new double[8]; for (i = 0; i < 8; i++) { inputVector[8][i] = threshImage[48 + i]; } // Line 8 inputVector[9] = new double[8]; for (i = 0; i < 8; i++) { inputVector[9][i] = threshImage[56 + i]; } return(inputVector); }
private string GenerateCompanyName() { var index = RandGen.Next(0, _companyNames.Count); return(_companyNames.AsEnumerable().ElementAt(index)); }
public string GenerateRandomPlaceName() { var index = RandGen.Next(0, _placeNames.Length); return(_placeNames[index]); }
private string GenerateStreetPrefix() { var index = RandGen.Next(0, _prefixs.Count); return(_prefixs.AsEnumerable().ElementAt(index).ToLower().UppercaseWords()); }
private string GenerateMaleSuffix() { var index = RandGen.Next(0, _maleSuffix.Count); return(_maleSuffix.AsEnumerable().ElementAt(index)); }
/// <summary> /// Create and Initialize partitions for the given service instance . /// </summary> /// <param name="instance">Initialize partitions for this service instance</param> /// <param name="isRandomPartitionType">true - if the partition type is selected randomly - String or Int64</param> /// <param name="type">Set the partition type to this parameter, if isRandomPartitionType is false. /// Singleton type is not allowed as we will set this type if instance partitions count = 1</param> /// <param name="int64PartitionKeyLowValMultiplier"></param> static void InitializePartitions(InstanceRecord instance, bool isRandomPartitionType, PartitionKeyType type, int int64PartitionKeyLowValMultiplier) { // Singletone is not a valid type VS.Assert.IsTrue(type != PartitionKeyType.Singleton, "unexpected partition key type {0} in StartSessionManagersForServiceInstance", type); // Ensure we have a valid partitions count > 0 Uri instanceName = instance.InstanceName; int partitionCount = instance.CountOfPartitions; VS.Assert.IsTrue(partitionCount > 0, "unexpected partitionCount {0} in StartSessionManagersForServiceInstance", partitionCount); // singleton case if (partitionCount == 1) { PartitionRecord newPartition = new PartitionRecord( instanceName, PartitionKeyType.Singleton, null, new IntegerPartitionKeyRange()); instance.Partitions[0] = newPartition; return; } bool stringPartitions = false; // randomly allocate string or int64 partition type. if (isRandomPartitionType) { stringPartitions = (RandGen.Next() % 2) == 0; // decide if we have string or int64 partitions } else { if (type == PartitionKeyType.StringKey) { stringPartitions = true; } } for (int i = 0; i < partitionCount; i++) { PartitionRecord newPartition; if (stringPartitions) { // string partition key string partitionKey = i.ToString(CultureInfo.InvariantCulture); newPartition = new PartitionRecord( instanceName, PartitionKeyType.StringKey, partitionKey, new IntegerPartitionKeyRange()); instance.Partitions[i] = newPartition; LogHelper.Log("Created; Instance: {0} StringPartition: {1}", instanceName, partitionKey); } // numerical partition key -- single number range IntegerPartitionKeyRange partitionInt64Key = new IntegerPartitionKeyRange { IntegerKeyLow = i * int64PartitionKeyLowValMultiplier, IntegerKeyHigh = i * int64PartitionKeyLowValMultiplier + (RandGen.Next() % (int64PartitionKeyLowValMultiplier - 1)) }; newPartition = new PartitionRecord( instanceName, PartitionKeyType.Int64Key, null, partitionInt64Key); instance.Partitions[i] = newPartition; LogHelper.Log("Created; Instance: {0} Int64Partition: {1}-{2}", instanceName, partitionInt64Key.IntegerKeyLow, partitionInt64Key.IntegerKeyHigh); } }
/// <summary> /// Setup a session from source partition to target partition. /// </summary> /// <param name="sessionTest"></param> /// <param name="sourcePartition"></param> /// <param name="targetPartition"></param> private void SetupSessionTest(SessionTest sessionTest, PartitionRecord sourcePartition, PartitionRecord targetPartition) { VS.Assert.IsFalse(sourcePartition == targetPartition, "sourcePartition {0} equals targetPartition {1} in SetupSessionTests", sourcePartition, targetPartition); IReliableSessionManager sourceSessionManager = sourcePartition.SessionManager; Uri targetSvcInstance = targetPartition.InstanceName; string targetEndpoint = targetPartition.Endpoint; Task <IReliableMessagingSession> newOutboundSessionTask = null; bool testSkipped = false; try { // Setup the outbound session from source to target partition switch (targetPartition.PartitionType) { case PartitionKeyType.Singleton: newOutboundSessionTask = sourceSessionManager.CreateOutboundSessionAsync(targetSvcInstance, targetEndpoint, new CancellationToken()); break; case PartitionKeyType.StringKey: string targetStringKey = targetPartition.StringPartitionPartitionKey; newOutboundSessionTask = sourceSessionManager.CreateOutboundSessionAsync(targetSvcInstance, targetStringKey, targetEndpoint, new CancellationToken()); break; case PartitionKeyType.Int64Key: IntegerPartitionKeyRange targetInt64Key = targetPartition.Int64PartitionPartitionKey; long rangeSize = targetInt64Key.IntegerKeyHigh - targetInt64Key.IntegerKeyLow + 1; long targetPartitionNumber = targetInt64Key.IntegerKeyLow + (RandGen.Next() % rangeSize); newOutboundSessionTask = sourceSessionManager.CreateOutboundSessionAsync(targetSvcInstance, targetPartitionNumber, targetEndpoint, new CancellationToken()); break; } VS.Assert.IsNotNull(newOutboundSessionTask, "Null newOutboundSessionTask in SetupSessionTests"); newOutboundSessionTask.Wait(); sessionTest.OutboundSession = newOutboundSessionTask.Result; } catch (System.AggregateException e) { Exception inner = e.InnerException.InnerException; VS.Assert.AreEqual(inner.GetType(), typeof(System.Runtime.InteropServices.COMException), "Unexpected AggregateException {0} from CreateOutboundSessionAsync", inner.GetType().ToString()); // Due to random nature of source and target selection, it might be possible we create a duplicate selection. // in this case, we skip the test. System.Runtime.InteropServices.COMException realException = (System.Runtime.InteropServices.COMException)inner; uint hresult = (uint)realException.ErrorCode; uint expectedError = (uint)NativeTypes.FABRIC_ERROR_CODE.FABRIC_E_RELIABLE_SESSION_ALREADY_EXISTS; VS.Assert.AreEqual(expectedError, hresult, "Unexpected error HRESULT code {0} from CreateOutboundSessionAsync", hresult); testSkipped = true; LogHelper.Log("Test# skipped due to {0} exception ", hresult); } if (testSkipped) { sessionTest.SkipTest = true; } else { // initialize snapshot test and open the session for message communication. sessionTest.OutboundSession.OpenAsync(new CancellationToken()).Wait(); sessionTest.InboundSession = targetPartition.InboundSessions[sourcePartition.PartitionKey]; sessionTest.SnapshotOutbound = sessionTest.OutboundSession.GetDataSnapshot(); sessionTest.SnapshotInbound = sessionTest.InboundSession.GetDataSnapshot(); VS.Assert.IsFalse(sessionTest.InboundSession == sessionTest.OutboundSession, "sourcePartition equals targetPartition in SetupSessionTests"); } }
public static PartitionRecord GetRandomPartitionRecord(InstanceRecord[] instances) { InstanceRecord randomInstanceRecord = instances[RandGen.Next(instances.Count())]; return(randomInstanceRecord.Partitions[RandGen.Next(randomInstanceRecord.CountOfPartitions)]); }
private string GenerateFemaleMiddleName() { var index = RandGen.Next(0, _femaleMiddleNames.Count); return(_femaleMiddleNames.AsEnumerable().ElementAt(index)); }
public string GenerateRandomLastName() { var index = RandGen.Next(0, _lastNames.Length); return(_lastNames[index]); }
//Generate Random Prefix Can Be Bool private bool RandomlyPickIfPrefixWillBeIncluded() => RandGen.Next(0, 2) == 0;
public string GenerateRandomMaleFirstName() { var index = RandGen.Next(0, _maleFirstNames.Length); return(_maleFirstNames[index]); }
/// <summary> /// Allows you to generate new last name /// </summary> /// <returns></returns> public string GenerateLastName() { return(_lastNames.AsEnumerable().ElementAt(RandGen.Next(0, _lastNames.Count))); }
private bool RandomlyPickIfNameIsMale() { IsMaleName = RandGen.Next(0, 2) == 0; return(IsMaleName); }