Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Random Characters with Multiple Lines

  • Random Characters with Multiple Lines

    Posted by Michael James on April 30, 2017 at 9:18 pm

    I’m trying to add a source text expression to a multi-line text layer where it’ll change every character randomly (limited to A-Z, 0-9) at a specific speed. For instance, if the text layer has two lines with 10 characters each, the expression would keep that exact format but change each character to a different random character, over and over again, at a specific speed.

    This expression sort of does what I need, however it doesn’t seem to dynamically preserve the original text format like number of characters and number of lines.

    c = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'];
    s = "";
    for(x=0; x < value.length; x++){
    r = Math.floor(random(0, c.length));
    s += c[r];
    }
    s

    It also cycles through random characters every frame, which I’d like to control how often the characters change. (ie every 4 frames) How would I go about this expression?

    Thanks!
    -MJ

    Michael James replied 9 years, 4 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    April 30, 2017 at 10:40 pm

    This should work:


    c = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'];
    s = "";
    spl = value.split("\r");
    for (i = 0; i < spl.length; i++){
    for (j = 0; j < spl[i].length; j++){
    r = Math.floor(random(0, c.length));
    s += c[r];
    }
    if (i != spl.length-1) s += "\r";
    }
    s

    Dan

  • Michael James

    April 30, 2017 at 10:56 pm

    Hey Dan,

    Thanks! This works almost perfectly. Is there a variable I can add to the expression to customize the speed in which the characters change? Right now they cycle once every frame. Would there a variable to change the cycle to once every 4 frames or once every 2 frames?

    -MJ

  • Dan Ebberts

    April 30, 2017 at 11:08 pm

    Try this:


    c = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'];
    framesPerChange = 4;
    seed = Math.floor(timeToFrames(time)/framesPerChange);
    seedRandom(seed,true);
    s = "";
    spl = value.split("\r");
    for (i = 0; i < spl.length; i++){
    for (j = 0; j < spl[i].length; j++){
    r = Math.floor(random(0, c.length));
    s += c[r];
    }
    if (i != spl.length-1) s += "\r";
    }
    s

    Dan

  • Michael James

    April 30, 2017 at 11:11 pm

    Works perfectly! Thank you so much for your help! Really appreciate it.

    -MJ

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