vb.net - Generating a new random number for each iteration -


the following code attempting position pieces @ random positions on board:

function selectplayer()     dim rand new random()     dim player integer = rand.next(0, 3)     return player end function  function selectpiece()     dim rand new random()     dim piece integer = rand.next(0, 4)     return piece end function   sub randomiseboard(byref board(,) string)      dim players() string = {"w", "b", "  "}     dim pieces() string = {"g", "e", "n", "m"}      rankno = 1 boarddimension         fileno = 1 boarddimension             board(rankno, fileno) = players(selectplayer) & pieces(selectpiece)         next     next  end sub 

the type of piece chosen array, containing character represents them, , combined player (b / w) uniquely define piece.

when executed, board generated, same piece positioned in every square.

each time code run, new piece generated , displayed. yet - not select unique piece each iteration.

why this? how can solve this?

initialize random-number generator.

randomize() 

then generate random value


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -