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. If it is possible, however, by doing something like hard-coding a value, how would that be done?
I have tried an extremely basic approach, but it has obviously failed: 3 = random.randint(60,900000)
.
Advertisement
Answer
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.