ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP 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:
Dell PowerEdge Servers
  #1  
Old May 20th, 2003, 07:59 AM
colombani colombani is offline
hum...
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Brazil
Posts: 24 colombani User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question array sorting

I need a array with x numbers (1 to x) mixed. Like this:

Using 4 numbers (1 to 4), i need:

array(1) = 3
array(2) = 2
array(3) = 4
array(4) = 1

This is random. I make this:

Code:
x = 4
randomize

array(1)=Int((x) * Rnd + 1)

array(2)=Int((x) * Rnd + 1)
while array(2) = array(1)
	array(2)=Int((x) * Rnd + 1)
wend

array(3)=Int((x) * Rnd + 1)
while (array(3) = array(2)) or (array(3) = array(1))
	array(3)=Int((x) * Rnd + 1)
wend

array(4)=Int((x) * Rnd + 1)
while (array(4) = array(3)) or (array(4) = array(2)) or (array(4) = array(1))
	array(4)=Int((x) * Rnd + 1)
wend


But, in this case, if x is a big number (like 100), the code will be very big too...
Any idea?

Thanks in advance

Ricardo

Reply With Quote
  #2  
Old May 20th, 2003, 10:02 AM
imbrokn imbrokn is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2001
Location: NJ
Posts: 428 imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 34 m 8 sec
Reputation Power: 10
Send a message via AIM to imbrokn
lets see if i remember by bubble sort from my programming classes in school

PHP Code:
function BubbleSort(arr)
  for 
0 to uBound(arr
     for 
i to Ubound(arr
        if 
arr(a) < arr(ithen
         
'swap values
         tmp = arry(i)
         arr(i) = arr(a) 
         arr(a) = tmp
       end if 
     next 
  next 
 BubbleSort = arr
end function 


I just tested it and it works. if you do a search on google for bubble sort it will tell you how it works. Basicall it finds the lowest value and puts it in the 1st index position, then the second lowest and puts it in the second index position and so on. This is a pretty effective way to sort an array and pretty common.

Last edited by imbrokn : May 20th, 2003 at 10:05 AM.

Reply With Quote
  #3  
Old May 20th, 2003, 12:06 PM
colombani colombani is offline
hum...
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Brazil
Posts: 24 colombani User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sorry, I didn't express myself well.
I want a array with shuffled numbers, and not ordened numbers. The array contains numbers, 1 to x, ordered randomly (each time the order is different), like in my code (above).

Thank you

Regards,
Ricardo

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > array sorting


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 5 hosted by Hostway