math - Function to generate randomly incrementing number over time -
i'm trying make fake download count. should increment randomly on time. download-count-like patterns nice.
is possible without using database, or storing counter anywhere?
my idea check number of seconds have passed since app released. throw formula spits out fake download count. users can request see download count @ time.
is there math function increments randomly? pass secondspassed there , scale how i'd like.
something this: getdownloadcount(secondspassed)

edit: here's example solution. gets worse performance on time.
downloadcount = 0 loop secondspassed/60 times // loop 1 more time every minute passed downloadcount += seededrandom(0, 10)
making fake download count doesn't sound nice thing do. in designing secure communication protocols, there legitimate use cases monotonically growing functions randomness in values.
i assuming have:
- a growth model given monotonically growing function providing approximate values desired function.
- access time stamp, never decreases.
- ability store constant random seed along function definition.
- no way store updated data upon function being queried.
first decide on window length, control how randomness in final output. expect want on order of 1 hour or few.
figure out window current time within. evaluate reference function @ start , end of window. consider rectangle given start , end time of window min , maximum value given reference function. feed corners of rectangle , constant seed prng. use prng choose random point within rectangle. point on final curve.
perform same computation 1 of neighbor windows. neighbor window use depend on whether first computed point on curve left or right of current time.
now have 2 points on curve (which reproducible , consistent), have iterate following procedure.
you given 2 points on final curve. consider rectangle given corners. feed corners , constant seed prng. use prng chose random point within rectangle. point on final curve. discard 1 of outer points, no longer needed.
since y-values restricted integers, procedure terminate once 2 points on curve have identical y-coordinate, , know, function has constant between 2 points.
Comments
Post a Comment