0

I have to integrate to some device that needs to generate some id this device has no SDK or API but, I have found some project in python that works fine.

for now, iv tested the option to run the python script as a process but it's not good option.

Code :


TRANSID_PREFIX = 'web'
def genTransId(self, trans_type=TRANSID_PREFIX):
        def float2hex(f):
            MAXHEXADECIMALS = 15
            w = f // 1
            d = f % 1

            # Do the whole:
            if w == 0: result = '0'
            else: result = ''
            while w:
                w, r = divmod(w, 16)
                r = int(r)
                if r > 9: r = chr(r+55)
                else: r = str(r)
                result =  r + result

            # And now the part:
            if d == 0: return result

            result += '.'
            count = 0
            while d:
                d = d * 16
                w, d = divmod(d, 1)
                w = int(w)
                if w > 9: w = chr(w+55)
                else: w = str(w)
                result +=  w
                count += 1
                if count > MAXHEXADECIMALS: break

            return result

        now = datetime.today()
        return trans_type+"!" + float2hex(random.random() * math.pow(2, 32)).lower() + "!" + str(int((time.mktime(now.timetuple())*1e3 + now.microsecond/1e3)))
1
  • The Python code is mainly just doing some math—so it seems like it would be relatively easy to convert to C#. You don't say why you think running the script as a process is "not good option", but if nothing else, I think doing would be overkill for something as trivial what this code is doing (as well as relatively slow). Commented May 26, 2019 at 14:06

1 Answer 1

1

Tool to convert python to c# and https://github.com/uxmal/pytocs

But, can you give some more info on your statement: "iv tested the option to run the python script as a process but it's not good option" ?

Sign up to request clarification or add additional context in comments.

1 Comment

and it's not a good option because it will be on a computer that doesn't use python

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.