6. Introduce a variable to represent the state of the user input
Currently you have:
Dim guess As Integer = -1
Do
Console.Write("Enter a guess between " + MinValue.ToString() + " and " + MaxValue.ToString() + ": ")
If Not Integer.TryParse(Console.ReadLine(), guess) Then
guess = -1
End If
Loop Until guess >= MinValue And guess <= MaxValue
Return guess
but you could instead go for something like:
Dim guess As Integer = -1
Dim validInput As Boolean = false
Do
Console.Write("Enter a guess between " + MinValue.ToString() + " and " + MaxValue.ToString() + ": ")
validInput = Integer.TryParse(Console.ReadLine(), guess)
Loop Until validInput And guess >= MinValue And guess <= MaxValue
Return guess
(Apologies if that doesn't build - I'm from C# land).
That way, you don't set the value of guess
if it's invalid and the intent is clearer.
7 (maybe). Reuse the same instance of System.Random
.
I think you're already doing this - my VB.NET knowledge is weak (I'm fromagain, C# land). The default constructor for Random
seeds the generator with a time-dependant seed, so multiple instances created in (very) quick succession will give the same values.