Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old May 19th, 2003, 09:35 AM
JeffTerry JeffTerry is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 3 JeffTerry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Identifying Singular Parts of Arrays

Okay here's my problem. I want to generate 4 random numbers, yet I don't want any of them to be the same. I need to know if theres a way (while using arrays) to say
Loop While number(#'s) = number(1 to 3)
so that i dont have to type
Loop while number(#'s) = number(1) or number(2) or number(3)
because i'm going to be working with a very large array and i still need all the numbers which are randomly generated to be unique.

Dim number(1 To 4) As Integer

Private Sub Command1_Click()
number(1) = Int((4 - 1 + 1) * Rnd + 1)
Do
number(2) = Int((4 - 1 + 1) * Rnd + 1)
Loop While number(2) = number(1)
Do
number(3) = Int((4 - 1 + 1) * Rnd + 1)

''''''''''''''''''I get an error here on next line (error = crash)

Loop While number(3) = number(1 Or 2)
Do
number(4) = Int((4 - 1 + 1) * Rnd + 1)

''''''''''''''''''I get an error here too on next line (error = crash)

Loop While number(4) = number(1 Or 2 Or 3)

Label1.Caption = number(1)
Label2.Caption = number(2)
Label3.Caption = number(3)
Label4.Caption = number(4)
End Sub

Last edited by JeffTerry : May 19th, 2003 at 01:18 PM.

Reply With Quote
  #2  
Old May 19th, 2003, 01:16 PM
JeffTerry JeffTerry is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 3 JeffTerry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile

Help would be much appreciated...

Reply With Quote
  #3  
Old May 19th, 2003, 02:01 PM
epl epl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Dublin
Posts: 413 epl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 18 m 18 sec
Reputation Power: 8
Not checked for errors and probably not too efficient:
Code:
dim i as integer, j as integer, r as double
dim random(0 to LARGE_NUMBER) as double
  for i=0 to LARGE_NUMBER
    do:let r=rand()
      for j=0 to i-1
        if r=random(j) then exit for
      next j
      if j=i then
        let random(i)=r
        exit do
      end if
    loop
  next i

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Arrays...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway