View Single Post
  #3   Spotlight this post!  
Unread 30-07-2012, 20:30
Kristian Calhoun's Avatar
Kristian Calhoun Kristian Calhoun is offline
Celebrating 20 years of 25
FRC #0025 (Raider Robotix)
Team Role: Mentor
 
Join Date: Oct 2005
Rookie Year: 2006
Location: No. Brunswick, NJ
Posts: 1,077
Kristian Calhoun has a reputation beyond reputeKristian Calhoun has a reputation beyond reputeKristian Calhoun has a reputation beyond reputeKristian Calhoun has a reputation beyond reputeKristian Calhoun has a reputation beyond reputeKristian Calhoun has a reputation beyond reputeKristian Calhoun has a reputation beyond reputeKristian Calhoun has a reputation beyond reputeKristian Calhoun has a reputation beyond reputeKristian Calhoun has a reputation beyond reputeKristian Calhoun has a reputation beyond repute
Send a message via AIM to Kristian Calhoun
Re: Replacing duplicates in a randomly generated array

One way to represent a set is by using a bit array:
  1. Create an array of size (max - min + 1).
  2. Initialize each element of this bit array to 0.
  3. When you generate a random number, x, check the value of the element in the bit array at index [x - min].
    • If the bit array value is 0, set the value at [x-min] in the bit array to 1.
    • If the bit array value is 1, then x already exists in the set, so generate another random number.
  4. Repeat the process until you've added setSize number of elements to the set.
__________________
Raider Robotix: Home | Twitter | Facebook | Instagram
Brunswick Eruption: Home | Twitter | Facebook

Last edited by Kristian Calhoun : 30-07-2012 at 21:06.