Github user grkvlt commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/134#discussion_r64399832
  
    --- Diff: 
utils/common/src/main/java/org/apache/brooklyn/util/text/Identifiers.java ---
    @@ -87,29 +87,34 @@
          * in general this is preferable to base64 as is more portable,
          * can be used throughout javascript (as ID's which don't allow +)
          * or as java identifiers (which don't allow numbers in the first char)
    -     **/
    -    public static String makeRandomId(int l) {
    -        //this version is 30-50% faster than the old double-based one, 
    -        //which computed a random every 3 turns --
    -        //takes about 600 ns to do id of len 10, compared to 10000 ns for 
old version [on 1.6ghz machine]
    -        if (l<=0) return "";
    +     * <p>
    +     * <b>NOTE</b> This version is 30-50% faster than the old double-based 
one,
    +     * which computed a random every 3 turns -- takes about 600 ns to do id
    +     * of len 10, compared to 10000 ns for old version [on 1.6ghz machine]
    +     */
    +    public static String makeRandomId(int l, String validStartChars, 
String validNonStartChars) {
    +        if (l <= 0) return "";
             char[] id = new char[l];
    -        int d = random.nextInt( (26+26) * (26+26+10) * (26+26+10) * 
(26+26+10) * (26+26+10));
    +        int s = validStartChars.length();
    +        int n = validNonStartChars.length();
    +        int d = random.nextInt(s * n * n * n * n);
    --- End diff --
    
    @neykov Good catch, suppose we could change to a long, or reduce to 
re-randomising after less characters...


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to