- Home /
Algorithm for number generation that is random but consistent
I am trying to make a number generator that will create a random number but as long as the input number is the same the output will be the same. Does anybody know of an article for generating an algorithm that will do this?
I do not want a consistent output for each input.
I also want the algorithm to be low cost. It is going to be run many times on a weekly basis and the game is going to be mobile based.
One idea I have is to use the date in the input for the algorithm, that way it is consistent among the players, but it will create a different output for each input on a daily basis.
Answer by tanoshimi · Jul 07, 2016 at 05:38 PM
You appear to contradict yourself:
"As long as the input number is the same the output will be the same"
"I do not want a consistent output for each input"
Which behaviour do you want?
RNGs don't have an "input": they generate a sequence of numbers using an algorithm based on a seed value. If you supply the same seed, you'll get the same sequence.
You haven't said what you need the number for, but it sounds like you might be looking for a hash function instead, which generates a deterministic output from any input.
Yes, he contradicts himself. He probably means he wants something far more "varied" than say y=3x+5.
@tanoshimi: I want a number generator for my social game that changes the in game economy globally. So, lets say an item has a value of 13 one week, the next week I would like it to have a different value, but the same value for every user. When I say I don't want a consistent output, I mean I don't want it to be a function that says, if value = 13 then value = 15. I want something more along the lines of if value = 13 and date is 3/03/16 then value = 15. Does that make sense?
Sorry for the confusion, I'm not always the best at explaining myself.
I don't think this is a good answer. Please post comments as comments :)
If it's a social game you have clients that connect to a server? If so, just generate this week's random number on the server using any method you like, and let all the clients synchronise to that value rather than generate it themselves...
Answer by mmehrten · Jul 16, 2016 at 06:55 AM
You could generate a sequence that you store on a server and then send to clients, assuming that your users are connected to a webserver. Or you could deploy the game with a list of ~1000 sequences and just use a different list item every day.