Click here to Skip to main content
15,887,027 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: bandwidth question Pin
Rilhas19-May-07 10:03
Rilhas19-May-07 10:03 
Questiongenerate unrepeated serials Pin
samira forooghi28-Mar-07 20:05
samira forooghi28-Mar-07 20:05 
AnswerRe: generate unrepeated serials Pin
Nathan Addy29-Mar-07 15:19
Nathan Addy29-Mar-07 15:19 
AnswerRe: generate unrepeated serials Pin
Tim Paaschen29-Mar-07 20:18
Tim Paaschen29-Mar-07 20:18 
GeneralRe: generate unrepeated serials Pin
Nathan Addy30-Mar-07 7:38
Nathan Addy30-Mar-07 7:38 
GeneralRe: generate unrepeated serials Pin
Tim Paaschen1-Apr-07 20:40
Tim Paaschen1-Apr-07 20:40 
GeneralRe: generate unrepeated serials [modified] Pin
cp98761-Apr-07 21:13
cp98761-Apr-07 21:13 
GeneralRe: generate unrepeated serials Pin
Nathan Addy2-Apr-07 8:58
Nathan Addy2-Apr-07 8:58 
Agreed. The original post asked for "unrepeated" and "nonconsecutive". By itself, this is really easy (10^6, 10^6 +2, 10^6 + 4, ...), and so I simply assumed he misasked his question.

Specifically I assumed that he wanted a random sample from that range without replacement. Like I told him, without getting a better requirements list, it wasn't going to be possible to answer his question properly.

Assuming he means "a random sample without replacement", I think my method (just generate the numbers) is best. The only problem here is that there aren't any guarantees they are unequal.

If you could "fudge" the randomness a bit, a previous poster came up with a good method (although in his method, you should put the random portion of the numbers first, then the sequential part, to maximize randomness). That method would generate 100K numbers that will be close to uniformly distributed.

You could also generate the numbers randomly and just keep the already generated ones sorted, so you can just check to see if they are in the list. This would produce the most accurate result, although also would take the most work (you'd have to do an extra insert and search into some data structure for each of your 100K iteration).

Finally, if you are comfortable with the theoretical foundations of random number generators, you might have some interesting possibilities there. As you might know, many of the most common RNGs are "Linear congruential RNGS". Each RNG of this type is defined by 3 numbers, a, b, and m. You start with an initial seed, n_0, and the number that comes out is (a*n_0 + b) mod m. That is your random number. By reapplying the formula with the JUST generated number will get you your second random number and so on. As far as this class of generators goes, there is an art and a science to picking "good" numbers" I think if you worked at it for an hour, you could figure out how to pick a, b, and m such that you could get a "uniform random without replacement" sample of 100K. I would guess this could be "the best" way, but it would require a little mathematical knowledge (nothing you can't get in a couple hours on wikipedia), and if you didn't know what you were doing, it would be pretty easy to mess it up. (I haven't looked at this in a while, but I think if you pick a prime as close to (10^17 - 10^16) as possible, and then get REALLY REALLY big a and b, you'd be ok.)

On the other hand, if unique and non-consecutive is REALLY what he wants, the following will do the trick:

std::vector<double> myVector;
myVector.reserve(100000);
int inserted = 0;
double baseNum = pow(10, 16);
while (inserted != 100000)
{
myVector.push_back(baseNum);
baseNum += 2;
}

will do exactly that.
GeneralRe: generate unrepeated serials Pin
cp98762-Apr-07 15:38
cp98762-Apr-07 15:38 
Questionhelp me Pin
phowarso28-Mar-07 4:38
phowarso28-Mar-07 4:38 
AnswerRe: help me Pin
Newbie0028-Mar-07 5:34
Newbie0028-Mar-07 5:34 
GeneralRe: help me Pin
phowarso28-Mar-07 5:56
phowarso28-Mar-07 5:56 
GeneralRe: help me Pin
phowarso28-Mar-07 5:56
phowarso28-Mar-07 5:56 
AnswerRe: help me Pin
cp987628-Mar-07 17:19
cp987628-Mar-07 17:19 
QuestionChess genetic algorithm Pin
blashey25-Mar-07 4:01
blashey25-Mar-07 4:01 
AnswerRe: Chess genetic algorithm Pin
Paul Conrad14-Jul-07 10:20
professionalPaul Conrad14-Jul-07 10:20 
QuestionRough Set Algorithm Pin
kkadir24-Mar-07 14:05
kkadir24-Mar-07 14:05 
AnswerRe: Rough Set Algorithm Pin
Paul Conrad21-Jul-07 18:06
professionalPaul Conrad21-Jul-07 18:06 
QuestionCube and Rectangle Intersection Pin
jk chan23-Mar-07 3:03
jk chan23-Mar-07 3:03 
AnswerRe: Cube and Rectangle Intersection Pin
Dan Neely23-Mar-07 3:20
Dan Neely23-Mar-07 3:20 
QuestionMath research team maps E8! Pin
73Zeppelin19-Mar-07 20:09
73Zeppelin19-Mar-07 20:09 
AnswerRe: Math research team maps E8! Pin
Maximilien20-Mar-07 3:17
Maximilien20-Mar-07 3:17 
JokeRe: Math research team maps E8! Pin
Dan Neely20-Mar-07 5:33
Dan Neely20-Mar-07 5:33 
GeneralRe: Math research team maps E8! Pin
DavidNohejl20-Mar-07 6:48
DavidNohejl20-Mar-07 6:48 
GeneralRe: Math research team maps E8! Pin
El Corazon20-Mar-07 7:10
El Corazon20-Mar-07 7:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.