diff --git a/README.md b/README.md index 44d6e75..085d6c4 100644 --- a/README.md +++ b/README.md @@ -18,70 +18,23 @@ Usage Example ### REST API - http://localhost:62456/api/randint32 - < -1741405968 + http://localhost:62456/api/randint32?length=3 + < {"type": "string", "format": "int32", "length": 3, "data": [1524492492, -1194151004, 1365408501], "success": "true"} - http://localhost:62456/api/randuniform - < 0.20340009994 + http://localhost:62456/api/randuniform?length=2 + < {"type": "string", "format": "uniform", "length": 2, "data": [0.07230273403292031, 0.733570206706375], "success": "true"} - http://localhost:62456/api/randnormal - < 1.02206840644 + http://localhost:62456/api/randnormal?length=1 + < {"type": "string", "format": "normal", "length": 1, "data": [0.6430985466029758], "success": "true"} - http://localhost:62456/api/randbytes?length=16 - < ���E��s_�b����G� - - -### WebSocket API - - ws://localhost:62456/ws - > RANDINT32 - < 585865374 - - > RANDUNIFORM - < 0.70137183786 - - > RANDNORMAL - < -1.6120135370 - - > RANDBYTES 32 - < �����9L).�!:���@Nh������d����_q� - - > SUBSCRIBEINT32 - < 1361330636 - < -604581511 - < 1510923919 - < ... - > UNSUBSCRIBE - < UNSUBSCRIBED - - > SUBSCRIBEUNIFORM - < 0.54623951886 - < 0.67567578799 - < 0.09746421443 - < ... - > UNSUBSCRIBE - < UNSUBSCRIBED - - > SUBSCRIBENORMAL - < -1.6120135370 - < 0.02943381135 - < -0.9883458007 - < ... - > UNSUBSCRIBE - < UNSUBSCRIBED - - > SUBSCRIBEBYTES 8 - < �K����{� - < I]������ - < ���.�t�U - < ... - > UNSUBSCRIBE - < UNSUBSCRIBED + http://localhost:62456/api/randhex?length=2&size=5 + < {"type": "string", "format": "hex", "length": 2, "size": 5, "data": ["b90e1b01bc", "b59374fc0e"], "success": "true"} License ------- Copyright (c) 2020 Andika Wasisto + Modified by Tobias Raayoni Last / Randonauts Co. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/quanttp/__main__.py b/quanttp/__main__.py index 0d0e669..e3faa53 100644 --- a/quanttp/__main__.py +++ b/quanttp/__main__.py @@ -31,7 +31,6 @@ from geventwebsocket.handler import WebSocketHandler from quanttp.data.qng_wrapper_linux import QngWrapperLinux from quanttp.data.qng_wrapper_windows import QngWrapperWindows - app = Flask(__name__) sockets = Sockets(app) @@ -40,39 +39,39 @@ qng_wrapper = QngWrapperWindows() if (os.name == 'nt') else QngWrapperLinux() @app.route('/api/randint32') def randint32(): try: - size = int(request.args.get('size')) - if size < 1: - return Response('size must be greater than 0', status=400, content_type='text/plain') + length = int(request.args.get('length')) + if length < 1: + return Response('length must be greater than 0', status=400, content_type='text/plain') int32array = [] - for x in range(0, size): + for x in range(0, length): int32array.append(qng_wrapper.randint32()) - return Response(json.dumps({"type": "string", "format": "int32", "length":1, "data": int32array, "success": "true"}), content_type='text/plain') + return Response(json.dumps({"type": "string", "format": "int32", "length":length, "data": int32array, "success": "true"}), content_type='text/plain') except (TypeError, ValueError) as e: return Response(json.dumps({"error": str(e), "success":"false"}), status=400, content_type='text/plain') @app.route('/api/randuniform') def randuniform(): try: - size = int(request.args.get('size')) - if size < 1: - return Response('size must be greater than 0', status=400, content_type='text/plain') + length = int(request.args.get('length')) + if length < 1: + return Response('length must be greater than 0', status=400, content_type='text/plain') uniformarray = [] - for x in range(0, size): + for x in range(0, length): uniformarray.append(qng_wrapper.randuniform()) - return Response(json.dumps({"type": "string", "format": "uniform", "length":1, "data": uniformarray, "success": "true"}), content_type='text/plain') + return Response(json.dumps({"type": "string", "format": "uniform", "length":length, "data": uniformarray, "success": "true"}), content_type='text/plain') except (TypeError, ValueError) as e: return Response(json.dumps({"error": str(e), "success":"false"}), status=400, content_type='text/plain') @app.route('/api/randnormal') def randnormal(): try: - size = int(request.args.get('size')) - if size < 1: - return Response('size must be greater than 0', status=400, content_type='text/plain') + length = int(request.args.get('length')) + if length < 1: + return Response('length must be greater than 0', status=400, content_type='text/plain') normarray = [] - for x in range(0, size): + for x in range(0, length): normarray.append(qng_wrapper.randnormal()) - return Response(json.dumps({"type": "string", "format": "normal", "length":1, "data": normarray, "success": "true"}), content_type='text/plain') + return Response(json.dumps({"type": "string", "format": "normal", "length":length, "data": normarray, "success": "true"}), content_type='text/plain') except (TypeError, ValueError) as e: return Response(json.dumps({"error": str(e), "success":"false"}), status=400, content_type='text/plain') @@ -86,9 +85,9 @@ def randhex(): if size < 1: return Response('size must be greater than 0', status=400, content_type='text/plain') hexarray = [] - for x in range(0, size): - hexarray.append(qng_wrapper.randbytes(length).hex()) - return Response(json.dumps({"type": "string", "format": "hex", "length":1, "size": length, "data": hexarray, "success": "true"}), content_type='text/plain') + for x in range(0, length): + hexarray.append(qng_wrapper.randbytes(size).hex()) + return Response(json.dumps({"type": "string", "format": "hex", "length":length, "size": size, "data": hexarray, "success": "true"}), content_type='text/plain') except (TypeError, ValueError) as e: return Response(json.dumps({"error": str(e), "success":"false"}), status=400, content_type='text/plain')