Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Stan James:
Does that makes sense?
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Peter Chase:
I can think of a most-bogus solution, along the lines of Bogosort. That is: compute all the possible strings, then choose one at random. However, the memory and computational costs of this are ridiculous.
Any ideas?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Originally posted by fred rosenberger:
you're gonna have a problem here... a 20 character string is going to require a random number between 0 and 2,432,902,008,176,640,000. since the OP said "arbitrary length", i would assume 20, 50 or even 100 it not out of the question.
or, wait... i think i did 20!, i should have done 26^20, which gives us
19,928,148,895,209,409,152,340,197,376
[ January 25, 2006: Message edited by: fred rosenberger ]
Originally posted by Paul Clapham:
You must choose length N with probability C^N * (C-1) / (C^(M+1) - 1).
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
They are what you said they were in your original question.Originally posted by Peter Chase:
For the record, this one sounds the most feasible so far. I'm not sure that I quite see what N, M and C are, but guess I could work it out.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Originally posted by fred rosenberger:
I have not done any math, but you mayhave a problem with George's solution...
if i undertand it correctly, he's saying whatever your max length is, generate a random string the full length. then, scan it to see if there is an imbedded 0.
for large max lengths, there are going to be a LOT of strings you'll have to reject, i think. it may take a while to find a valid one.
i'm not SURE of this, it's just my intuition (whatever that's worth...).
"I'm not back." - Bill Harding, Twister
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Originally posted by Paul Clapham:
They are what you said they were in your original question.
However if C is 94, then the probability of choosing a string of anything less than the maximum length M (or Lmax as you called it later) is almost exactly 1/94 (regardless of what M is) and the probability of choosing a string of the maximum length is 93/94. So you might simplify the problem to only choose strings of length M -- a major simplification.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Originally posted by Stefan Wagner:
... at least until random.nextInt (94) isn't broken
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
"I'm not back." - Bill Harding, Twister
Reid - SCJP2 (April 2002)
"I'm not back." - Bill Harding, Twister
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Reid - SCJP2 (April 2002)
"I'm not back." - Bill Harding, Twister
Reid - SCJP2 (April 2002)
Reid - SCJP2 (April 2002)
I think the API documentation for Random's nextInt() method sheds some light on why that is, and possibly suggests how you could write your own nextLong() method.Originally posted by Reid M. Pinchback:
Unfortunately there isn't a Random.nextLong(range) method, so I just modded by the range - and that seems to be torqueing the distribution.
Don't get me started about those stupid light bulbs. |