Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
158 views
in Technique[技术] by (71.8m points)

python - Is it possible to set the value of an integer to another?

If, for simulation purposes, it was essential that a compiler took the value of one integer and in its stead used another value when doing some sort of calculation, how would the value of that integer be altered? I have found various answers on setting the value of a variable to that of another, but I don't believe it would be possible to use the same concepts to achieve the desired result. I am also aware that this may not be achievable at all as it is would probably be necessary to tweak with the language or the compiler or something. I have tried an extremely basic approach, but it has obviously failed: 3 = random.randint(60,900000).

What I was trying to do was develop an almost true random number generator (still technically pseudorandom). The initial value would be put through a formula with an integer which's value would be set to (for example) random.randint(60,900000). The number returned would be more 'random' than anything possible with a regular pseudorandom number.

question from:https://stackoverflow.com/questions/65647161/is-it-possible-to-set-the-value-of-an-integer-to-another

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

While this question has the distinct hallmark of an XY problem, the essential point of the question is, how can I get a different value while I'm testing my code as opposed to when I'm actually running the code?

Fundamentally speaking, this can be accomplished in a myriad of ways:

  • Mock the service that generates that integer and supply it with whatever integer you want
  • Inject the service in design, and replace it with your own while testing, so you can then generate whatever integer you wish
  • Hard-coding it (if you really had to)

If your question were clearer, you could get an explicit answer on how to solve your problem. This is just a generic remark to that effect.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...