When screen tapped randomly generate code?

I tried doing this on my own but failed majorly, could anyone help me with a brief example on the best way to achieve this?

Here’s a link showing what I’m kind of trying to do:
http://www.hackertyper.com

@Bathix10, I just looked at the site pretty quickly, but it doesn’t seem to be random, it gives the same result everytime. You could something similar using this code: (hold the screen)

function setup()
    str = [[public static boolean isSmallStraight(List<Die> dice) {

        boolean result = false;

        List<Die> copy = new ArrayList<Die>(dice);
        Collections.sort(copy);

        List<Die> testCase1 = new ArrayList<Die>();
        testCase1.add(new Die(1));
        testCase1.add(new Die(2));
        testCase1.add(new Die(3));

        if(copy.containsAll(testCase1)) {
            result = true;
            System.out.println(result);
        }

        return result;

    }]]

    disp = 0

    touching = false
end

function draw()
    background(255)
    
    fill(0) fontSize(WIDTH / 35) textWrapWidth(WIDTH * 7/8) textAlign(LEFT)
    
    text(str:sub(0, disp), WIDTH / 2, HEIGHT / 2)


    if touching then
        disp = disp + 60 * DeltaTime
    end
end

function touched(t)
    if t.state == BEGAN then
        touching = true
    elseif t.state == ENDED then
        touching = false
    end
end

(untested, typed in browser)

@Bathix10, I’ve changed my code above to use the text you’ve provided

Works nicely, I’m just trying to replace the str with this

public static boolean isSmallStraight(List<Die> dice) {

        boolean result = false;

        List<Die> copy = new ArrayList<Die>(dice);
        Collections.sort(copy);

        List<Die> testCase1 = new ArrayList<Die>();
        testCase1.add(new Die(1));
        testCase1.add(new Die(2));
        testCase1.add(new Die(3));

        if(copy.containsAll(testCase1)) {
            result = true;
            System.out.println(result);
        }

        return result;

    }

I’m trying to make that stay with all the spaces in the text and not all bunched together but it errors?

Like it’s just random code like the webpage

Thanks very much for this, when I add a lot to the text it falls behind when it starts getting down at the end of the screen and then deletes all the text? I’m not sure if it’s a bug I fixed you code to only generate when tapped not hold.

Here’s the text that does that bug.

    function setup()
    str = [[public static boolean isSmallStraight(List<Die> dice) {

        boolean result = false;

        List<Die> copy = new ArrayList<Die>(dice);
        Collections.sort(copy);

        List<Die> testCase1 = new ArrayList<Die>();
        testCase1.add(new Die(1));
        testCase1.add(new Die(2));
        testCase1.add(new Die(3));

        if(copy.containsAll(testCase1)) {
            result = true;
            System.out.println(result);
        }

        return result;
    
       public class CardGameTester
{
  public static void main(String[] args)
  {
    ArrayList<Card> hand = new ArrayList<Card>();
    Deck d = new Deck();

    Scanner scan = new Scanner(System.in);
    System.out.println("Welcome to the game of Black Jack!\
Would you like to Start?");
    String input = scan.nextLine();
    if(input == "yes")
    {
      d.deal();
      hand.add(d);
    }

    String input2;

    while (input2 == "yes")
    {
      Scanner keyboard = new Scanner(System.in);
      System.out.println("Would you like to hit or stay?");
      input2 = keyboard.nextLine();
      d.deal();
      hand.add(d);
    }

    int total;

    for(int index = 0; index <= hand.size(); index++)
    {
      total = hand.get(index);
    }

    System.out.println("Your total value for you cards are: " + total);

    if(total <= 21){
      System.out.println("Congrats, you have won for not going over 21");
    }
    else
      {
        System.out.println("Sorry, you lose for going over 21");
    }
  }
}
    }]]
    

    disp = 0

end  

function draw()
    
    background(0, 0, 0, 255)

    fill(0, 255, 22, 255) fontSize(25) textWrapWidth(WIDTH)  textAlign(LEFT)

    text(str:sub(0, disp), WIDTH / 2, HEIGHT / 2)
        
    if touching then
    disp = disp + 60 * DeltaTime
    touching=false
    end

            
function touched(t)    
            
     if t.state == BEGAN then
        touching = true
    
    if t.state == ENDED then
        touching = false   
             end
        end       
    end
end

Without looking to closely, your touched function is messed up. Try this:

function touched(t)    

     if t.state == BEGAN then
        touching = true
     end

    if t.state == ENDED then
        touching = false   
    end
end

EDIT: Your draw as well, you need an extra end

@Bathix10 As for all the text being deleted, when using the text function you can’t exceed a size of 1024 or the text disappears. In other words, if the w or h of w,h=textSize(string) is greater than 1024, the text function doesn’t show anything.

How can I fix this?

If you’re talking about the text not showing, one way is to only show text that will fit on the screen. As you increase the size of disp, you need to increase the starting point of the text statement. The statement text(str:sub(0,disp) should be changed to something like text(str:sub(start,disp) so that the “start” position can be changed to keep the w or h of w,h=textSize(string) less than 1024. The only problem is, it won’t be that easy. As you show more text at the end, whenever you reach a new line character, you’ll have to change the “start” value.