# VB.NET non-repeating random number



## Ciberblade (Sep 22, 2003)

I am trying to write a method that I can pass in two values (low number, high number) and will return a non-repeating random number within this range, one number at a time (possibly button click, not sure yet - I'll tackle that later). Once all available numbers are used, I want it to return a -1. I cannot move on until I get this tested functionally. I am trying to make use of a binary array to keep track of used numbers by index. Here is what I have so far:

Any ideas?


----------



## Chicon (Jul 29, 2004)

Hi ciberblade,

My first thought was to use the old VB6 rnd function, but after having read this :
http://www.dotnet247.com/247reference/msgs/26/131087.aspx ...

There are solutions to your problem.


----------



## Ciberblade (Sep 22, 2003)

Chicon ~ thanks for the reference :up:

I ended up setting a counter equal to the size of my array, then incrementing that counter each time through the loop - using that to index my boolean. It is satisfying


----------

