Timeline for How to randomize letters in a word
Current License: CC BY-SA 3.0
11 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 12, 2016 at 21:36 | comment | added | Tim Čas |
-14 bytes for non-range-check version if you use C strings and in-place shuffle: void f(char*s){random_shuffle(s+1,s+strlen(s)-1);} . Another -1 for technically-undefined int instead of void return type (with missing return statement). Might work even without range checks (despite technical UB with <start_of_mem_region>-1 ) --- I don't know the behavior of random_shuffle if last < first , and it depends on that in that case.
|
|
Aug 4, 2011 at 16:12 | comment | added | Tomalak | Things I've learned: I'll be more careful with the specs next time. That, and there are quite a lot of languages I don't understand the least bit about. | |
Aug 4, 2011 at 10:43 | history | edited | Konrad Rudolph | CC BY-SA 3.0 |
Shorter code, overflow check added.
|
Aug 4, 2011 at 10:30 | comment | added | Konrad Rudolph | @user 1/6 isn’t terribly much, and I complied with the OP’s specs. But I’ll change it. | |
Aug 4, 2011 at 10:06 | comment | added | user unknown | At least 1/6 had it right from the start. Lame excuses are for wusses, imho. :) | |
Aug 4, 2011 at 7:02 | comment | added | Konrad Rudolph | @userunknown That’s what I meant by “overflow checks are for wusses”. But to be fair, so do almost all other solutions. | |
Aug 4, 2011 at 6:43 | comment | added | Tomalak | That's true, you're missing a length check (I did, as well). BTW @Arlen's answer is also worth a look. | |
Aug 4, 2011 at 4:02 | comment | added | user unknown | Fails for very short strings. | |
Aug 3, 2011 at 15:59 | comment | added | Tomalak | Something like that is what I had in mind originally. Unfortunately there is no built-in for shuffling a string in-place in JS. | |
Aug 3, 2011 at 15:48 | comment | added | Scott Logan |
Nice, std::random_shuffle , that's a new one to me. btw I think you forgot #include<string> in your full code.
|
|
Aug 3, 2011 at 15:41 | history | answered | Konrad Rudolph | CC BY-SA 3.0 |