Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions IP4 number generator

  • IP4 number generator

    Posted by Navarro Parker on July 31, 2012 at 6:30 pm

    I’ve got this expression running, but I need leading zeros if any of the values fall beneath 100. Any suggestions?

    a = random(198,255).toFixed(0);
    b = random(000,255).toFixed(0);
    c = random(000,255).toFixed(0);
    d = random(000,255).toFixed(0);
    a + " :" + b + ":" + c + ":" + d;

    Dan Ebberts replied 13 years, 10 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    July 31, 2012 at 6:58 pm

    One way:

    a = random(198,255).toFixed(0);
    b = random(000,255).toFixed(0);
    c = random(000,255).toFixed(0);
    d = random(000,255).toFixed(0);
    while (a.length < 3) a = “0” + a;
    while (b.length < 3) b = “0” + b;
    while (c.length < 3) c = “0” + c;
    while (d.length < 3) d = “0” + d;
    a + ” :” + b + “:” + c + “:” + d;

    Dan

  • Navarro Parker

    July 31, 2012 at 11:12 pm

    Perfect! Thank you!!

  • Navarro Parker

    October 22, 2012 at 7:24 pm

    How something more complicated like IPv6? (8 groups of 4 hexidecimal numbers each separated by colons)

    such as: 2001:0DB8:02A2:B3FF:FE1E:FF00:0042:8329

  • Dan Ebberts

    October 22, 2012 at 7:43 pm

    Like this maybe:


    s = "";
    seedRandom(index,true);
    for (i = 0; i < 8; i++){
    s += (i == 0) ? "" : ":";
    for (j = 0; j <= 3; j++){
    s += Math.floor(random(16)).toString(16).toUpperCase();
    }
    }

    Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy