I need to call a python script from C# Blazor WASM using IronPython 2.7. The reason I need to call python is that this is a legacy application that was originally a PHP server app that would call the python script from the filesystem to produce a pseudo-random string based upon a string seed.
I haven't found any good examples on how to do this. Here is the PY script:
#! /usr/bin/env python
# answerkey.py
""" generate 'random' answer keys """
import sys
from random import random, seed
SHUFFLE = 1000
ANS = ('A','B','C','D')
ANS_CT = 50
def makeKeys(group, key_ct, ans_ct=ANS_CT, ans=ANS):
"""
create tuple(key_ct) of tuple(ans_ct) of 'randomized' answers.
group - group name of answers (actually random 'seed')
ans - sequence of possible answers (default ('A','B','C','D'))
ans_ct - number of answers in key (default 50)
key_ct - number of different keys to generate
"""
l = []
while len(l) < ans_ct:
l.extend(list(ans))
# difference between 32-bit and 62-bit random seed
seed(hash(group) & 0xffffffff)
ct = len(l)
r =[]
for i in range(key_ct):
i = SHUFFLE
while i > 0:
e1 = int(random() * ct)
e2 = int(random() * ct)
if e1 != e2:
l[e1],l[e2]=l[e2],l[e1]
i -= 1
# r.append(tuple(l[:ans_ct]))
r.append(''.join(l[:ans_ct]))
return r
if __name__ == '__main__':
x = makeKeys(sys.argv[1], int(sys.argv[2]))
for i in x:
print (I)
Suggesions?