Skip to main content

Timeline for Random String generator in C

Current License: CC BY-SA 3.0

14 events
when toggle format what by license comment
Aug 5, 2018 at 20:26 comment added autistic On the note of using int, everywhere you use int you include the possibility that a compiler for a given architecture might introduce sign handling overhead... probably best to use size_t for things like sizes or indexes of arrays. It'll all end up in a register, at the end of the day anyway, but this way it might end up in a better register in some cases.
Feb 2, 2018 at 13:14 comment added Toby Speight Just to point out (I'm sure you know, but you didn't make it explicit), sizeof charset works for const char charset[] but is wrong for const char *charset.
Feb 26, 2017 at 3:20 review Suggested edits
Feb 26, 2017 at 4:15
Aug 1, 2013 at 0:09 comment added William Morris Added some notes to my answer on allocating vs passing a buffer
Aug 1, 2013 at 0:07 history edited William Morris CC BY-SA 3.0
Added reason for not allocating
Jul 31, 2013 at 20:56 comment added AntonioCS @WilliamMorris Could you provide some more insight on why you pass the buffer and not just create the buffer in the string with malloc and return it? Is it because this way it would be easier to free the memory? Is it not possible to free the returned pointer? Thanks.
Jul 31, 2013 at 20:51 vote accept AntonioCS
Jul 31, 2013 at 0:50 comment added William Morris The questioner is asking specifically about C, not C++, not Java, not go, python etc. Thanks for your input.
Jul 30, 2013 at 21:00 history edited William Morris CC BY-SA 3.0
Corrected silly mistake
Jul 30, 2013 at 20:17 comment added Quonux your right, if you speak of easy life you grab c++,java,go,python,haskell,ruby or d unless your really need the last 100%-20% performance or your forced to use c
Jul 30, 2013 at 20:12 comment added William Morris That is true but many standard library functions do this too. It can make life easier, eg in printf("%s\n", rand_string(buf, sizeof buf));
Jul 30, 2013 at 20:09 comment added Quonux note that you don't need to return any result because the str parameter is mutable
Jul 30, 2013 at 20:06 history edited William Morris CC BY-SA 3.0
Added example code
Jul 30, 2013 at 19:56 history answered William Morris CC BY-SA 3.0