diff --git a/concepts/randomness/.meta/config.json b/concepts/randomness/.meta/config.json index 40af6cd05e..9d3d06b430 100644 --- a/concepts/randomness/.meta/config.json +++ b/concepts/randomness/.meta/config.json @@ -1,5 +1,8 @@ { "blurb": "The System.Random class can be used to generate pseudo-random integral or floating-point numbers.", "authors": ["mikedamay"], - "contributors": ["ErikSchierboom"] + "contributors": [ + "ErikSchierboom", + "yrahcaz7" + ] } diff --git a/concepts/randomness/about.md b/concepts/randomness/about.md index 3a02eeb769..8c1e25610a 100644 --- a/concepts/randomness/about.md +++ b/concepts/randomness/about.md @@ -4,33 +4,41 @@ In C# applications randomness is generally implemented using the `System.Random` This [article][system-random] is an excellent introduction to the subject. -When becoming familiar with a library class it is always worth studying the [documentation][system-random] for properties and methods and their overloads. +When becoming familiar with a library class, it is always worth studying the [documentation][system-random] for properties and methods and their overloads. -The coding exercise highlighted a number of issues: +The coding exercise highlighted a number of aspects: - The random number generator does not require a [seed][random-seedless]. -- `Random.Next()` can generate a range of integers -- `Random.Double()` can generate a double between 0 and 1 -- The upper bounds in `Next...()`, `Double()` and `Sample()` are **exclusive** so that `Random.Next(1,19)` will yield values from 1 to 18 but not 19. -- Once you have your random number you can do what you like with it +- `Random.Next()` can generate a range of integers. +- `Random.NextDouble()` can generate a double between 0 and 1. +- The upper bounds in `Next()`, `NextDouble()`, and `Sample()` are **exclusive** so that `Random.Next(1,19)` will yield values from 1 to 18 but not 19. +- Once you have your random number, you can do what you like with it. There are 3 patterns for implementing the last point: -- You can get the random number and manipulate it. In the case of the coding exercise this would consist of calling `Random.NextDouble()` and multiplying by 100. This [piece][random-use-case-array] discusses making random selections from an array. +- You can get the random number and manipulate it. + In the case of the coding exercise, this would consist of calling `Random.NextDouble()` and multiplying by 100. + This [piece][random-use-case-array] discusses making random selections from an array. - You can inherit from `System.Random` and override the `Sample()` method. - You can encapsulate an instance of `System.Random` as a member of a class of your own, for example [to generate Booleans][random-use-cases]. The numbers generated by `Random` are not guaranteed to be unique. -It is [recommended][random-thread-safety] that you instantiate `System.Random` as a static member. But, note that it is not thread safe. +It is [recommended][random-thread-safety] that you instantiate `System.Random` as a static member. +But, note that it is not thread safe. -You may see documentation discouraging the use of seedless constructors. This mostly applies to .NET Framework rather than .NET Core (which is what _Exercism_ uses). For the full story read [this][random-multiple-instantiations]. +You may see documentation discouraging the use of seedless constructors. +This mostly applies to .NET Framework rather than .NET Core (which is what _Exercism_ uses). +For the full story read [this][random-multiple-instantiations]. -You are advised not to use `System.Random` for crypto or security. See this [provider][crypto-provider] and this [number generator][crypto-rng]. +You are advised not to use `System.Random` for crypto or security. +See this [provider][crypto-provider] and this [number generator][crypto-rng]. ## Thread safety -When applied in the context of library APIs "not thread safe" is simply shorthand for saying that, if you are likely to access instances of the class through multiple concurrent [threads][threading], you should provide your own thread synchronization mechanisms or, in the case of collections, look at the possibility of using a concurrent version of the class. In the absence of these precautions, [race conditions][so-race-conditions] are likely to occur. If your code base does not use multiple threads, and is not likely to, then this warning is of little concern. +When applied in the context of library APIs, "not thread safe" is simply shorthand for saying that, if you are likely to access instances of the class through multiple concurrent [threads][threading], you should provide your own thread synchronization mechanisms or, in the case of collections, look at the possibility of using a concurrent version of the class. +In the absence of these precautions, [race conditions][so-race-conditions] are likely to occur. +If your code base does not use multiple threads, and is not likely to, then this warning is of little concern. [system-random]: https://docs.microsoft.com/en-us/dotnet/api/system.random [random-thread-safety]: https://docs.microsoft.com/en-us/dotnet/api/system.random diff --git a/concepts/randomness/introduction.md b/concepts/randomness/introduction.md index f49401bb66..2e9bf48898 100644 --- a/concepts/randomness/introduction.md +++ b/concepts/randomness/introduction.md @@ -1,3 +1,4 @@ # Introduction -In C# randomness is achieved with the help of `System.Random`. Typically, you create an instance and then call one of its `Next()` or `NextDouble()` methods, possibly multiple times depending on the use-case. +In C# randomness is achieved with the help of `System.Random`. +Typically, you create an instance and then call one of its `Next()` or `NextDouble()` methods, possibly multiple times depending on the use-case. diff --git a/exercises/concept/roll-the-die/.docs/hints.md b/exercises/concept/roll-the-die/.docs/hints.md index 75b46b724d..0430bc53f3 100644 --- a/exercises/concept/roll-the-die/.docs/hints.md +++ b/exercises/concept/roll-the-die/.docs/hints.md @@ -4,14 +4,14 @@ This [article][system-random] is an excellent introduction to the subject. -## 1. Enable a wizards and warriors player to roll a die. +## 1. Enable a _Wizards and Warriors_ player to roll a die This [article][random-integers] explains how to generate integers. ## 2. Players need their strength. Provide a means to generate spell strength -This [article][random-reals] explains how to generate real numbers. +This [article][random-floating-point] explains how to generate floating-point numbers. [system-random]: https://docs.microsoft.com/en-us/dotnet/api/system.random [random-integers]: https://docs.microsoft.com/en-us/dotnet/api/system.random.next -[random-reals]: https://docs.microsoft.com/en-us/dotnet/api/system.random.nextdouble +[random-floating-point]: https://docs.microsoft.com/en-us/dotnet/api/system.random.nextdouble diff --git a/exercises/concept/roll-the-die/.docs/instructions.md b/exercises/concept/roll-the-die/.docs/instructions.md index 13443d60b7..28fd4007b4 100644 --- a/exercises/concept/roll-the-die/.docs/instructions.md +++ b/exercises/concept/roll-the-die/.docs/instructions.md @@ -1,8 +1,11 @@ # Instructions -Continuing the theme of the wizards and warriors game, it is time to add an all purpose die rolling method. This will be the traditional 18 sided die with numbers 1 to 18. Players also generate a spell strength. +In this exercise, you are playing a role-playing game named "Wizards and Warriors." +To play this game, you need an all-purpose die rolling method to determine various outcomes. +This will be the traditional 18-sided die with numbers 1 to 18. +Players will also need to generate a random spell strength. -## 1. Enable a _wizards and warriors_ player to roll a die. +## 1. Enable a _Wizards and Warriors_ player to roll a die Implement a `RollDie()` method on the `Player` class. @@ -14,9 +17,10 @@ player.RollDie(); ## 2. Players need their strength. Provide a means to generate spell strength -Implement a `GenerateSpellStrength()` method on the player class. The spell strength is between 0.0 and up to but not including 100.0. +Implement a `GenerateSpellStrength()` method on the player class. +The spell strength is between 0.0 and up to but not including 100.0. -Note that spell strength must be a real number (not an integer) to reduce the possibility of a tie when the strengths of two adversaries are compared. +Note that spell strength must be a floating-point number (not an integer) to reduce the possibility of a tie when the strengths of two adversaries are compared. ```csharp var player = new Player(); diff --git a/exercises/concept/roll-the-die/.docs/introduction.md b/exercises/concept/roll-the-die/.docs/introduction.md index 9f98be975d..0483f96e78 100644 --- a/exercises/concept/roll-the-die/.docs/introduction.md +++ b/exercises/concept/roll-the-die/.docs/introduction.md @@ -2,4 +2,5 @@ ## Randomness -In C# randomness is achieved with the help of `System.Random`. Typically, you create an instance and then call one of its `Next()` or `NextDouble()` methods, possibly multiple times depending on the use-case. +In C# randomness is achieved with the help of `System.Random`. +Typically, you create an instance and then call one of its `Next()` or `NextDouble()` methods, possibly multiple times depending on the use-case. diff --git a/exercises/concept/roll-the-die/.meta/config.json b/exercises/concept/roll-the-die/.meta/config.json index 6051e60933..9b5f8495fb 100644 --- a/exercises/concept/roll-the-die/.meta/config.json +++ b/exercises/concept/roll-the-die/.meta/config.json @@ -6,7 +6,8 @@ "ErikSchierboom", "yzAlvin", "aage", - "karanchadha10" + "karanchadha10", + "yrahcaz7" ], "files": { "solution": [