realbasic-nug
[Top] [All Lists]

Re: Checking array for double entries

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: Checking array for double entries
From: Paul Young <youngpr@myactv.net>
Date: Sat, 28 Jun 2008 15:30:33 -0400
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <233017.99162.qm@web28006.mail.ukl.yahoo.com>
References: <233017.99162.qm@web28006.mail.ukl.yahoo.com>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com
Tobias,

You could sort the numbers, then compare each number to the next number. If the two are the same, delete one. At the end of the comparison, look at the total number of numbers and generate as many new ones as you need. Repeat the process until you have enough.

Paul Young


On Jun 28, 2008, at 3:22 PM, tobieichner77-rb@yahoo.de wrote:

Hello,

I wrote a small app that generates six random numbers out of a range from 1 to 70. The requirement is that no single number is used twice.

So far the only solution I came upon to prevent double entries is to compare all entries with each other. In the case of two equal entries, I simply re-create the random array again and do another check.

For example:

while x(1) = x(2) or x(1) = x(3) or x(1) = x(4) or x(1) = x(5) or x(1) = x(6) or x(2) = x(3) or x(2)= x(4) or x(2) = x(5) or x(2)= x(6) or x(3)= x(4) or x(3) = x(5) or x(3) = x(6) or x(4) = x(5) or x(4) = x(6) or x(5) = x(6)
   for y = 1 to 6 step 1
     x(y) = r.inrange(1,70)
   next
 wend

As you see, this leads to a long and ugly "or" chain, which will finally end into a total mess if there are, let's say, twenty numbers to compare with each other.

Can you give me a hint how I can manage this easier and more convenient ?

Bye,
Tobias.


     __________________________________________________________
Gesendet von Yahoo! Mail.
Dem pfiffigeren Posteingang.
http://de.overview.mail.yahoo.com

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>



_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>