Ejemplo n.º 1
0
        /// <summary>
        /// Generates a random point within this box.
        /// </summary>
        /// <param name="rand"></param>
        /// <returns></returns>
        public GeoCoordinate GenerateRandomIn(IRandomGenerator rand)
        {
            double lat = (double)rand.Generate(1.0) * this.DeltaLat;
            double lon = (double)rand.Generate(1.0) * this.DeltaLon;

            return(new GeoCoordinate(this.MinLat + lat,
                                     this.MinLon + lon));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Offsets this coordinate in a random direction.
        /// </summary>
        /// <param name="randomGenerator"></param>
        /// <param name="meter"></param>
        /// <returns></returns>
        public GeoCoordinate OffsetRandom(IRandomGenerator randomGenerator, Meter meter)
        {
            GeoCoordinate offsetCoordinate = this.OffsetWithDistances(meter.Value /
                                                                      System.Math.Sqrt(2));
            double offsetLat = offsetCoordinate.Latitude - this.Latitude;
            double offsetLon = offsetCoordinate.Longitude - this.Longitude;

            offsetLat = (1.0 - randomGenerator.Generate(2.0)) * offsetLat;
            offsetLon = (1.0 - randomGenerator.Generate(2.0)) * offsetLon;

            return(new GeoCoordinate(this.Latitude + offsetLat, this.Longitude + offsetLon));
        }
Ejemplo n.º 3
0
        public (int, int) GetStartAndEndIndexes(IRandomGenerator random, int gridsize)
        {
            List <int> edgeIndexes = GetGridEdgeIndexes(gridsize);
            int        startIndex  = edgeIndexes[random.Generate(0, edgeIndexes.Count - 1)]; // Select a random index on the EDGE of the maze as the start room.
            int        endIndex    = random.Generate(0, gridsize * gridsize - 1);            // Select a random index anywhere in the maze as the end room.

            if (startIndex == endIndex)
            {
                endIndex = (endIndex + 1) % (gridsize * gridsize); // Move end index up by 1, with overflow protection
            }

            return(startIndex, endIndex);
        }
Ejemplo n.º 4
0
        public (int, int) Roll()
        {
            int roll1 = RandomGenerator.Generate(NumSides);
            int roll2 = RandomGenerator.Generate(NumSides);

            if (roll1 == roll2)
            {
                LastRollWasDoubles = true;
            }
            if (roll1 != roll2)
            {
                LastRollWasDoubles = false;
            }

            return(roll1, roll2);
        }
Ejemplo n.º 5
0
        public Round Run(IEnumerable <UserInGame> userGames)
        {
            if (!_gameStarted)
            {
                throw new GameNotStartedException();
            }

            if (TotalRounds == CurrentRound)
            {
                throw new GameOverException();
            }

            var randomNumber = _randomGenerator.Generate(_maxGuessNo);

            var winner = userGames
                         .Select(u =>
                                 new
            {
                Id   = u.UserId,
                Diff = Math.Abs(u.Number - randomNumber)
            })
                         .OrderBy(a => a.Diff)
                         .First();

            CurrentRound++;

            RoundsLeft--;
            var lastRound = TotalRounds == CurrentRound;

            var newRound = new Round(Id, randomNumber, winner.Id, CurrentRound, lastRound);

            Rounds.Add(newRound);

            return(newRound);
        }
        public int MakeGuess(int min, int max)
        {
            var guess = _randomGenerator.Generate(min, max, _guessedNumbers);

            _guessedNumbers.Add(guess);

            return(guess);
        }
        protected override byte[] GenerateFileContent(int contentLength)
        {
            string generatedString = randomGenerator.Generate(contentLength);

            var bytes = Encoding.Unicode.GetBytes(generatedString);

            return(bytes);
        }
Ejemplo n.º 8
0
        public GeoCoordinate OffsetRandom(IRandomGenerator randomGenerator, Meter meter)
        {
            GeoCoordinate geoCoordinate = this.OffsetWithDistances((Meter)(meter.Value / System.Math.Sqrt(2.0)));
            double        num1          = geoCoordinate.Latitude - this.Latitude;
            double        num2          = geoCoordinate.Longitude - this.Longitude;

            return(new GeoCoordinate(this.Latitude + (1.0 - randomGenerator.Generate(2.0)) * num1, this.Longitude + (1.0 - randomGenerator.Generate(2.0)) * num2));
        }
Ejemplo n.º 9
0
        public IConnectionData Connect(INeuronData origin, INeuronData destination)
        {
            var connection = new ConnectionData(ReserveId(), weightRandom.Generate(), origin.Id, destination.Id);

            origin.OutConnectionIds.Add(connection.Id);
            destination.OutConnectionIds.Add(connection.Id);

            return(connection);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Checks wether the treasure hunter gets injured in a room.
        /// </summary>
        /// <param name="random">A random number generator.</param>
        /// <param name="roomId">ID of the room.</param>
        /// <returns></returns>
        public static bool TrapCheck(IRandomGenerator random, IMaze maze, int roomId)
        {
            bool injured = random.Generate() > maze.Rooms[roomId].BehaviourThreshold;

            if (injured)
            {
                maze.Rooms[roomId].Description += $" {maze.Rooms[roomId].Behaviour}";
            }
            return(injured);
        }
Ejemplo n.º 11
0
 public Task Write()
 {
     return(Task.Run(() =>
     {
         while (!_canceled)
         {
             var user = _generator.Generate <User>();
             _cosmosWriter.Write(user);
         }
     }));
 }
Ejemplo n.º 12
0
        public T NextItem()
        {
            if (_distribution.Count == 0)
            {
                return(default(T));
            }

            var next = _randomNumberGenerator.Generate(0, _distribution.Count);

            return(_distribution[next]);
        }
Ejemplo n.º 13
0
        public Card[] Shuffle(Card[] deck)
        {
            for (var n = deck.Length - 1; n > 0; --n)
            {
                var rand = _generator.Generate(n + 1);
                var temp = deck[n];
                deck[n]    = deck[rand];
                deck[rand] = temp;
            }

            return(deck);
        }
Ejemplo n.º 14
0
        public string GetTest()
        {
            Int32         number = _firstLineGenerator.Generate();
            string        result = number.ToString();
            StringBuilder temp   = new StringBuilder(2 * number);

            for (int i = 0; i < number; i++)
            {
                temp.Append(_linesGenerator.Generate().ToString());
                temp.Append("\n");
            }
            return(result + "\n" + temp.ToString());
        }
Ejemplo n.º 15
0
        public static void Shuffle <T>(this IList <T> list, IRandomGenerator random)
        {
            int count = list.Count;

            while (count > 1)
            {
                --count;
                int index = random.Generate(count + 1);
                T   obj   = list[index];
                list[index] = list[count];
                list[count] = obj;
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Shuffles the list using Fisher-Yates shuffle.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public static void Shuffle <T>(this IList <T> list, IRandomGenerator random)
        {
            var n = list.Count;

            while (n > 1)
            {
                n--;
                var k     = random.Generate(n + 1);
                T   value = list[k];
                list[k] = list[n];
                list[n] = value;
            }
        }
Ejemplo n.º 17
0
        private string FormatMovie(Movie movie)
        {
            var    pickSentenceStyle = m_randomGenerator.Generate(0, 5);
            string format;

            switch (pickSentenceStyle)
            {
            default:
            {
                format = $"<p>{movie.Name} <break strength=\"x-strong\" time=\"850ms\" /> läuft um {{0}}.</p>";
                break;
            }

            case 2:
            case 3:
            {
                format = $"<p>{movie.Name} <break strength=\"x-strong\" time=\"850ms\" /> wird um {{0}} gezeigt.</p>";
                break;
            }

            case 4:
            {
                format = $"<p>{movie.Name} <break strength=\"x-strong\" time=\"850ms\" /> beginnt um {{0}}.</p>";
                break;
            }

            case 5:
            {
                format = $"<p>{movie.Name} <break strength=\"x-strong\" time=\"850ms\" /> startet um {{0}}.</p>";
                break;
            }
            }

            var showTimes = movie.Vorstellungen.OrderBy(p => p.VorstellungTime)
                            .Select(p => MarkAsTime(p.VorstellungTime.ToString("hh\\:mm"))).ToList();

            string times;

            if (showTimes.Count > 1)
            {
                times = string.Format($"{string.Join(", ", showTimes.Take(showTimes.Count - 1))} und {showTimes.Last()}");
            }
            else
            {
                times = showTimes[0];
            }

            return(string.Format(format, times));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 获取文件名
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <returns></returns>
        private string GetFileName(string fileName)
        {
            var name      = Path.GetFileNameWithoutExtension(fileName);
            var extension = Path.GetExtension(fileName).TrimStart('.');

            if (string.IsNullOrWhiteSpace(extension))
            {
                extension = fileName;
                name      = string.Empty;
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                name = _randomGenerator.Generate();
            }
            return($"{name}.{extension}");
        }
Ejemplo n.º 19
0
        private void GenerateFood()
        {
            Point genPoint;

            do
            {
                genPoint = _randomGenerator.Generate();
                if (_emptyField.Count(point => point == genPoint) == 0)
                {
                    if (!_playerSnake.CheckingCollisions(genPoint, 0))
                    {
                        Food = genPoint;
                    }
                }
            } while (Food != genPoint);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Executes the mutation.
        /// </summary>
        /// <param name="solver"></param>
        /// <param name="mutating"></param>
        /// <returns></returns>
        public virtual Individual <GenomeType, ProblemType, WeightType> Mutate(
            Solver <GenomeType, ProblemType, WeightType> solver, Individual <GenomeType, ProblemType, WeightType> mutating)
        {
            double val  = _generator.Generate(1.0);
            double prob = 0;

            for (int idx = 0; idx < _probabilities.Count; idx++)
            {
                prob = prob + _probabilities[idx];
                if (prob > val)
                {
                    return(_operations[idx].Mutate(solver, mutating));
                }
            }
            throw new Exception("invalid probabilities!");
        }
Ejemplo n.º 21
0
        public int RollDice()
        {
            var progress = _randomGenerator.Generate();

            if (_currentProgress[_currentPlayer] + progress == 100)
            {
                _currentProgress[_currentPlayer] += progress;
                Finished = true;
                Winner   = _currentPlayer;
            }
            else if (_currentProgress[_currentPlayer] + progress < 100)
            {
                _currentProgress[_currentPlayer] += progress;
            }

            return(progress);
        }
Ejemplo n.º 22
0
        public RoomType GetRandomSafeRoomType(IRandomGenerator random)
        {
            IRoomFactory rf = new RoomFactory();

            RoomType[]      roomTypes = (RoomType[])Enum.GetValues(typeof(RoomType));
            List <RoomType> safeTypes = new List <RoomType>();

            foreach (var type in roomTypes)
            {
                var room = rf.Create(type);
                if (room.BehaviourThreshold == 1)
                {
                    safeTypes.Add(type);
                }
            }

            return(safeTypes[random.Generate(0, safeTypes.Count)]);
        }
Ejemplo n.º 23
0
        private void GenerateFood()
        {
            Point genPoint;

            while (true)
            {
                genPoint = _randomGenerator.Generate();
                if (_emptyField.Count(point => point.X == genPoint.X &&
                                      point.Y == genPoint.Y) == 0)
                {
                    if (_playerSnake.Body.Count(point => point.X == genPoint.X &&
                                                point.Y == genPoint.Y) == 0)
                    {
                        Food = genPoint;
                        return;
                    }
                }
            }
        }
Ejemplo n.º 24
0
        private async Task PublishRandom()
        {
            try
            {
                string randomMessage = await randomGenerator.Generate();

                SystemMessageEvent m = new SystemMessageEvent
                {
                    Created = DateTime.UtcNow,
                    Node    = Context.NodeContext.NodeName,
                    Service = Context.ServiceName.ToString().Split("/").Last(),
                    Message = randomMessage
                };

                ServiceEventSource.Current.ServiceMessage(Context, $"Publishing message: {nameof(SystemMessageEvent)}");

                await messagePublisher.PublishMessageAsync(m);
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceMessage(Context, e.Message);
            }
        }
Ejemplo n.º 25
0
        public (IRoom[], int, int) GenerateMaze(IRandomGenerator random, int gridsize)
        {
            IRoom[]      rooms = new IRoom[gridsize * gridsize];
            IRoomFactory rf    = new RoomFactory();

            var(startIndex, endIndex) = GetStartAndEndIndexes(random, gridsize);
            rooms[startIndex]         = rf.Create(GetRandomSafeRoomType(random));
            rooms[endIndex]           = rf.Create(GetRandomSafeRoomType(random));

            // List of all roomtypes.
            RoomType[] roomTypes = (RoomType[])Enum.GetValues(typeof(RoomType));

            for (int i = 0; i < rooms.Length; i++)
            {
                if (i == startIndex || i == endIndex)
                {
                    continue;
                }
                rooms[i] = rf.Create(roomTypes[random.Generate(0, roomTypes.Length)]); // Place a room of random type on each index.
            }

            return(rooms, startIndex, endIndex);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Offsets this coordinate in a random direction.
        /// </summary>
        /// <param name="randomGenerator"></param>
        /// <param name="meter"></param>
        /// <returns></returns>
        public GeoCoordinate OffsetRandom(IRandomGenerator randomGenerator, Meter meter)
        {
            GeoCoordinate offsetCoordinate = this.OffsetWithDistances(meter.Value /
                                             System.Math.Sqrt(2));
            double offsetLat = offsetCoordinate.Latitude - this.Latitude;
            double offsetLon = offsetCoordinate.Longitude - this.Longitude;

            offsetLat = (1.0 - randomGenerator.Generate(2.0)) * offsetLat;
            offsetLon = (1.0 - randomGenerator.Generate(2.0)) * offsetLon;

            return new GeoCoordinate(this.Latitude + offsetLat, this.Longitude + offsetLon);
        }
Ejemplo n.º 27
0
 public int GenerateRandomNumber()
 {
     return(_generator.Generate());
 }
Ejemplo n.º 28
0
 public Guid GetRandomDataNodeId()
 {
     return(_dataNodes.Keys.ElementAt(_randomGenerator.Generate(_dataNodes.Count())));
 }
Ejemplo n.º 29
0
 public string GetTest()
 {
     return(_generatorFirstObject.Generate() + " " +
            _generatorSecondObject.Generate().ToString());
 }
Ejemplo n.º 30
0
 public GeoCoordinate GenerateRandomIn(IRandomGenerator rand)
 {
     return(new GeoCoordinate(this.MinLat + rand.Generate(1.0) * this.DeltaLat, this.MinLon + rand.Generate(1.0) * this.DeltaLon));
 }
Ejemplo n.º 31
0
        /// <summary>
        /// Generates a random point within this box.
        /// </summary>
        /// <param name="rand"></param>
        /// <returns></returns>
        public GeoCoordinate GenerateRandomIn(IRandomGenerator rand)
        {
            double lat = (double)rand.Generate(1.0) * this.DeltaLat;
            double lon = (double)rand.Generate(1.0) * this.DeltaLon;

            return new GeoCoordinate(this.MinLat + lat,
                this.MinLon + lon);
        }
Ejemplo n.º 32
0
 public static string PickRandom(string[] Input, IRandomGenerator RandomGenerator)
 {
     return(Input[RandomGenerator.Generate(Input.Length - 1)]);
 }