.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 2nd, 2004, 01:54 PM
pcyopick pcyopick is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 5 pcyopick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Randomize Array

Ive made an online quiz in asp.net(vb), with the questions in an external xml document.

What the client wants is to randomize the questions. I currently loop through all the questions once the xml is parsed, so I thought making a randomized array of number of questions and going through the xml that way.

How would one make this randomized array, with each number appearing only once? Or is there any better ways of approaching this??

Thanks;

Paul Cyopick
cyopick@yahoo.com

Reply With Quote
  #2  
Old July 29th, 2004, 07:56 AM
gertjan gertjan is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 gertjan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb

I use this to randomize all arrays and other lists


///
<summary>
/// Randomizes the order of thr elements in any object that implements the IList interface.
/// If the object doesn't implement IList it is returned unchanged.
///</summary>
///<param name="org">Any object</param>
///<returns>object with elements in randomized order</returns>
publicstaticobject Shuffle (object org)
{
if (org is IList)
{
Random rnd = new Random();
IList arr = (IList)org;
int newPos;
object tempObj;
int index = arr.Count;
while (--index >= 0)
{
// new position for element at index
newPos = rnd.Next(arr.Count);
// swap the elements at newPos and index
tempObj = arr[index];
arr[index] = arr[newPos];
arr[newPos] = tempObj;
}
return arr;
}
return org;
}

Quote:
Originally Posted by pcyopick
Ive made an online quiz in asp.net(vb), with the questions in an external xml document.

What the client wants is to randomize the questions. I currently loop through all the questions once the xml is parsed, so I thought making a randomized array of number of questions and going through the xml that way.

How would one make this randomized array, with each number appearing only once? Or is there any better ways of approaching this??

Thanks;

Paul Cyopick
cyopick@yahoo.com

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > Randomize Array


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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT