0

I have a T-SQL code and I want to run a few simulations in Python. There is a code that includes random functions and I am not sure how I can replicate it.

When I have RAND() in SQL, I just use this in Python:

import random as random
print random.random()

But, I have also this code: RAND(CHECKSUM(NEWID()))

I guess, it is used for some kind of seed in the RAND function. But, how I can replicate the same thing in Python to have as much closer results I could?

1
  • I would appreciate if you could leave a comment when you vote for close. Otherwise, the same question could just reappear in the future. Commented Jun 2, 2016 at 9:02

1 Answer 1

1

in Python you need to first call

random.seed() in you program (once only)

then

random.random()

each time you want a random number

to give a pseudo random number from 0 to 1


yes RAND(CHECKSUM(NEWID())) appears to be a good trick to get a random value to use as a seed - it could be argued that a NEWID has a greater amount of randomness than using time as a seed. It depends on your application, time is considered insufficient as a seed for cryptography without adding other entropy - the python randomize uses time as a seed

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.