How to add a function to app context in flask

from flask import Flask
import random

class RandString:
    def rand_string(cls, st):  # st is just a string value
        a = random.randint(1, 10)
        return st * a

def create_app():
    app = Flask(__name__)

    with app.app_context():
        app.config['RAND_STRING'] = RandString

    def home():
        return 'HomePage'

    return app
def test():
    rand_fuction = current_app.config['RAND_STRING']
    return {'rand_string': rand_fuction(2)}