The following code is attempting to position pieces at random positions on a board:
Function selectPlayer()
Dim rand As New Random()
Dim player As Integer = rand.Next(0, 3)
Return player
End Function
Function selectPiece()
Dim rand As New Random()
Dim piece As Integer = rand.Next(0, 4)
Return piece
End Function
Sub randomiseBoard(ByRef Board(,) As String)
Dim players() As String = {"W", "B", " "}
Dim pieces() As String = {"G", "E", "N", "M"}
For RankNo = 1 To BoardDimension
For FileNo = 1 To BoardDimension
Board(RankNo, FileNo) = players(selectPlayer) & pieces(selectPiece)
Next
Next
End Sub
The type of piece is chosen from an array, containing the character which represents them, and combined with the player (B / W) to uniquely define a piece.
When executed, the board is generated, however the same piece is positioned in every square.
Each time the code is run, a new piece is generated and displayed. Yet - it does not select a unique piece for each iteration.
Why is this? How can I solve this?