The following sketch code does what you want. It is obvious that you don’t understand the code so I suggest that you do some basic research on object orientated programming (OO) and start with classes and objects
static class Example
{
static PApplet papp;
public static void init(PApplet papplet) {
papp = papplet;
}
public static int sum(int a, int b) {
return a+b;
}
public static float rand(float max) {
return papp.random(max);
}
}