p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_codeclinic thread: How to remove duplicate numbers in an array


Message #1 by "Jon Carlos" <j.b.carlos@w...> on Tue, 27 Feb 2001 10:54:42
Hi Jon,

You might want to consider the following - 

Put the code for generating a random number into a
function. Call the function every time you want to
generate a number for the sets. Store the generated
numbers in different variables or in an array. If the
number generated by the function is the same as the
value already stored in the variables or array member,
then you can call the function once again. So you keep
calling the function again and again till you find a
unique number.

Hope this helps,

regards,
Kart


--- Jon Carlos <j.b.carlos@w...> wrote:
> I'm currently programming a game of Bingo and want
> to randomly generate 
> the called numbers and put them in a database.
> 
> The numbers go like this:
> Set 1 numbers 1 to 15
> Set 2 numbers 16 to 30
> Set 3 numbers 31 to 45
> Set 4 numbers 46 to 60
> Set 5 numbers 61 to 75
> 
> No I can generate this with this code:
> 
> Dim rnum(10,5)
> 
> rmax=15
> rMin=1
> 
> For a = 1 to 5
> 
> 	For i = 1 to 10
> 
> 		Randomize
> 		rnum(i,a) = Int((rmax - rmin +1) * Rnd + rmin)
> 
> 	Next
> 
> 	Rmax = cint(rmax) + 15
> 	Rmin = cint(rmin) + 15
> 
> Next
> 
> But I dont want to have duplicate numbers in any of
> the sets.
> 
> As I can see it there are two ways of checking for
> duplicates.
> 
> 1: at the begining when generating the numbers
> 2: after all the numbers are generated
> 
> Problem 1 is I dont know to check for the duplicates
> Problem 2 is I dont know how to replace the
> duplicates with numbers that 
> havent been chosen.
> 
> Please Please Help
> 
> Thanks In advance
> 
> Jon
> ---
> http://www.asptoday.com - the leading site for
> timely,
> in-depth information for ASP developers everywhere.
> ---
> You are currently subscribed to proasp_codeclinic
> as: kk8877@y...
> $subst('Email.Unsub')
> 


__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/

  Return to Index