I want to generate a string mix of numbers-capital and small characters but they should be unique with a specific length Is there any algorithm or library in java to generate unique strings?
13835
I've been looking for a simple Java algorithm to generate a pseudo-random alpha-numeric string.  In my situation it would be used as a unique session/key identifier that would "likely" be unique over 500K+ generation (my needs don't really require anything much more sophisticated).    Ideally, I would be able to specify a length depending on my uniqueness needs. For example, a generated string of length 12 might look something like "AEYGF7K0DM1X".
69664
is there some generally available algorithm which will encrypt a short string and generate two unique keys so that any of the two can be used to decrypt the message again? It doesn't has to be "super secure".
52629
Is there any way I can specify a standard or custom numeric format string to always output the sign, be it +ve or -ve (although what it should do for zero, I'm not sure!)
107627
Is it the same convention as those used in known programming languages such as Java and C? I'm trying to create a lot of variables and I want it to start with a number, but I'm not sure if it's okay.
69830
So my question is that let's say I have a bit string of length four. If it is illegal to have 3 1's in a row and 3 0's in a row then how many bit string of this type exists  I was thinking that in total combination of bit strings of length four there is $2^4$, but in this case there is 2+2 illegal combinations so the total is   $2^4-4$ is this correct?
2328
Does anyone know of a really simple way of capitalizing just the first letter of a string, regardless of the capitalization of the rest of the string?  For example:  asimpletest -&gt; Asimpletest aSimpleTest -&gt; ASimpleTest   I would like to be able to do all string lengths as well.
75336
Someone told me it's more efficient to use StringBuffer to concatenate strings in Java than to use the + operator for Strings. What happens under the hood when you do that? What does StringBuffer do differently?
63537
Given an alphabet of size $n$, how many strings of length $c$ contain every single letter of the alphabet at least once?  I first attempted to use a recurrence relation to work it out:  $$ T(c) = \left\{ \begin{array}{cr} 0 &amp;\mbox{ if $c&lt;n$} \\ n! &amp;\mbox{ if $c = n$} \\ T(c-1) \cdot n \cdot c &amp;\mbox{ if $c &gt; n$} \end{array} \right. $$  As there's no strings that contain every letter if c &lt; n, and if c = n then it's just all permutations. When c > n you can take any string of size (c-1) that contains all letters (of which there are $T(c-1)$ to choose from), you choose which letter to add (of which there are $n$ choices) and there are $c$ different positions to put it. However, this gives out results that are larger than $n^c$ (the total number of strings), so it can't be right, and I realised it was because you could count some strings multiple times, as you can make them taking different inserting steps.   Then I thought about being simpler: you choose n positions in the string, put each letter of the alphabet in one of those positions, then let the rest of the string be anything:  $$ {c\choose{n}} \cdot n! \cdot n^{c-n} $$  But again this counts strings multiple times.  I've also considered using multinomial coefficients, but as we don't know how many times each letter appears in the string it seems unlikely they would be much help. I've also tried several other methods, some complicated and some simple, but none of them seem to work.  How would you go about working out a formula for this? I'm sure there's something simple that I'm missing.
5691
Is there a better way of getting this result? This function fails if num has more digits than digits, and I feel like it should be in the library somewhere (like Integer.toString(x,"%3d") or something)  static String intToString(int num, int digits) {     StringBuffer s = new StringBuffer(digits);     int zeroes = digits - (int) (Math.log(num) / Math.log(10)) - 1;      for (int i = 0; i &lt; zeroes; i++) {         s.append(0);     }     return s.append(num).toString(); }
67177
I'm looking to create a simple short-lived reservation system, and I'd like to generate confirmation numbers that are   unique random-looking alphanumeric short-ish, at least much shorter than 32 character-long strings returned by sha1   I'm only looking to have ~500 reservations, so I don't imagine high likelyhood of collissions.  One idea I had is generate an sha1 hash based on a date-time stamp and username, then truncating it to its first 10 characters.  Would something like that be reliably unique enough for the purposes of processing ~500 reservations?
36042
Duplicate:    I want an pseudo random number generator that can generate numbers with no repeats in a random order. For example: random(10) might return 5, 9, 1, 4, 2, 8, 3, 7, 6, 10 Is there a better way to do it other than making the range of numbers and shuffling them about, or checking the generated list for repeats?  Edit: Also I want it to be efficient in generating big numbers without the entire range.  Edit: I see everyone suggesting shuffle algorithms. But if I want to generate large random number (1024 byte+) then that method would take alot more memory than if I just used a regular RNG and inserted into a Set until it was a specified length, right? Is there no better mathematical algorithm for this.
62677
I am writing a Java utility which helps me to generate loads of data for performance testing.  It would be really cool to be able to specify a regex for Strings so that my generator spits out things which match this.  Is there something out there already baked which I can use to do this?  Or is there a library which gets me most of the way there?  Thanks
26280
What is an easy way in Python to format integers into strings representing thousands with K, and millions with M, and leaving just couple digits after comma?  I'd like to show 7436313 as 7.44M, and 2345 as 2,34K.  Is there some % string formatting operator available for that? Or that could be done only by actually dividing by 1000 in a loop and constructing result string step by step?
40270
I need to calculate no of possible substrings containing "00" as a substring. I know the length of the binary string.  Eg: for a string of length 4, possible substrings are: 0000 0001 0010 0011 0100 1000 1001 1100  I just need the number of possible combinations, not enumerate all of them.
38898
I need to format a decimal value into a string where I always display at lease 2 decimals and at most 4.   So for example  "34.49596" would be "34.4959"  "49.3" would be "49.30"   Can this be done using the String.format command? Or is there an easier/better way to do this in Java.
37193
What is the preferred way to remove spaces from a string in C++? I could loop through all the characters and build a new string, but is there a better way?
26810
How can I generate a (pseudo)random alpha-numeric string, something like: 'd79jd8c' in PHP?