Function for generating a random increase in number over time

I'm trying to fake download count . It should gradually increase with time. Some download-like templates would be nice.

Is this possible without using a database or storing the counter anywhere?

My idea is to check the number of seconds elapsed since the release of my application. Then just drop it into a formula that spits out a fake load count. Users can request a download counter at any time.

Is there a mathematical function that is gradually increasing? I could just pass my secondsPassed there and scale it as I would like.

Something like this: getDownloadCount(secondsPassed)

enter image description here

Edit: here is an example solution. But over time, it worsens.

 downloadCount = 0 loop secondsPassed/60 times // Loop one more time for every minute passed downloadCount += seededRandom(0, 10) 
+5
source share
9 answers

Creating fake downloads doesn't seem like a nice thing. However, when developing secure communication protocols, there are legal options for using monotonously growing functions with some randomness in their values.

I assume you have:

  • A growth model defined as a monotonically growing function that provides approximate values ​​for the desired function.
  • Access to a timestamp that never decreases.
  • The ability to store a constant random seed along with a function definition.
  • Unable to save updated data when requesting a function.

First, you determine the length of the window, which will control how random it will be in the final output. I expect you to want it to be on the order of one hour or more.

Indicate in which window the current time is located. Rate the reference function at the beginning and at the end of this window. Consider the rectangle given by the start and end time of the window, as well as the min and the maximum value of the specified reference function. Fill in the corners of this rectangle and your permanent seeds in PRNG. Use PRNG to select a random point inside the rectangle. This point will be on the final curve.

Perform the same calculation for one of the neighboring windows. Which neighboring window to use depends on whether the first calculated point is on the curve to the left or right of the current time.

Now that you have two points on the curve (which are reproducible and consistent), you will have to iterate the following procedure.

On the final curve you get two points. Consider the rectangle defined by these corners. Feed the corners and your perennial seeds in PRNG. Use this PRNG to select a random point inside the rectangle. This point will be on the final curve. Drop one of the outside points that is no longer needed.

Since Y values ​​are limited to integers, this procedure will eventually end as soon as your two points on the curve have the identical Y-coordinate, and you know that the function must be constant between these two points.

+1
source

You can implement a Morris counter .

It works as follows: start by setting the counter to 1. Every time you want to increase the count (which can be any iteration of a cycle or every time an event occurs, but does not have to be determined randomly), then you do a random procedure to determine the effect that it has on the counter.

This may be possibly ineffective, or it may lead to an increase in the order of magnitude of the count. The probability is based on whether n consecutive honest coin flags rotate heads, where n is the number of bits needed to encode the current counter value in binary format. As a result, once the counter has become quite high, it is very difficult to make it even higher (the state of the counter simulates the phenomenon when you are already overstating the count, so now you need a lot of things - events for compensation, making the count more accurate).

This is used as a cheap way to store a rough estimate of a very large collection, but there is no reason why you cannot use it as your randomly increasing counter device.

If you need higher accuracy or you want the counting outputs to be more "normal" numbers, and not always equal to 2, then you can simply create several Morris counters, and at each step the average number of incoming all of them.

+1
source

For some deterministic function f (possibly f(x) = x , or if your fake application is REALLY awesome f(x) = 2^x ) and a random function r that outputs a random number that is sometimes negative and sometimes positive.

Your graphical function g can be:

g(x) = f(x) + r

EDIT

How about this: https://gamedev.stackexchange.com/questions/26391/is-there-a-family-of-monotonically-non-decreasing-noise-functions

0
source

You are behind a sequence that always increases by a random amount, depending on how long you last requested the sequence.

This can be done using a random sequence that is always sown the same way.

Then each time we iterate over the same sequence to get a graph.

We need a function that increases our counter, saves a new time and quantity, and returns a count.

Ideally, we will model the increase in the form of a Poisson process, but here it will be linear.

 class Counter { private static int counter = 0; private static int time = 0; private static double rate = 5.0; private Random r; public Counter(int seed){ counter = 0; r = new Random(seed); } private int poisson(double rate, int diff){ // We're gonna cheat here and sample uniformly return r.Next(0, (int)Math.Round(rate * diff)); } public int getNext(int t){ var diff = t - time; time = t; if (diff <= 0) return counter; counter += this.poisson(rate, diff); return counter; } } void Main() { var c = new Counter(1024); for(var i = 0; i< 10; i++){ Console.WriteLine(String.Format("||{0}\t|{1}\t||",i,c.getNext(i))); } } 

These outputs (for example):

 ||t |hit|| ||0 |0 || ||1 |3 || ||2 |4 || ||3 |6 || ||4 |6 || ||5 |8 || ||6 |10 || ||7 |13 || ||8 |13 || ||9 |16 || 
0
source

Well, this is not "random", but you can use A*(X/B + SIN(X/B)) (scalable by some number) to introduce some noise. You can adjust A and B to change the scale of the result and the frequency of the “noise” cycles.

Indeed, any periodic function having a first derivative within certain limits can work.

0
source

as a quick solution, you can use something like this (code in java):

 static long f(final int x) { long r = 0; // initial counter long n = 36969L; // seed for (int i = 0; i <= x; i++) { n = 69069L * n + 1234567L; // generate Ith random number r += (n & 0xf); // add random number to counter } return r; } 

playing with the numbers 36969L and 0xf , you can achieve different results.

numbers 69069L and 1234567L are standard LCG

the main idea is to create a simple random one with the same seed and for each x passed (number of seconds) repeat random additions to the counter

0
source

A good model for random events such as downloads is the Poisson distribution. You must estimate the average number of downloads over a given period of time (an hour, say), and then invert the Poisson distribution to get the number of downloads over a period of time, given a uniformly distributed random number. For added realism, you can change the average value depending on the time of day, time of the week, etc. Sample algorithms are available at http://en.m.wikipedia.org/wiki/Poisson_distribution#Generating_Poisson-distributed_random_variables .

0
source

Here is a javascript implementation of a “fake” boot counter that seems the same for everyone. This always returns the same results for each each time and does not require a database or files for this. It also gracefully handles a case where you are not requesting new data at the same time, it will look natural the next time you request a day. enter image description here https://jsfiddle.net/Lru1tenL/1/

 Counter = { time:Date.now(), count:0, rate:0.45 }; Counter.seed = function(seed, startTime) { this.time = startTime, this.count = 0, this.prng = new Math.seedrandom(seed); this.prng.getRandomInt = function(min, max) { return Math.floor(this() * (max - min)) + min; }; }; Counter.getNext = function(t){ var diff = t - this.time; console.log(diff); if(diff <= 0) return this.count; this.time = t; var max = Math.ceil(diff/100 * this.rate); console.log("max: " + max); this.count += this.prng.getRandomInt(0,max); return this.count; }; var results = []; var today = Date.now(); Counter.seed("My Random Seed", today); for (var i = 0; i < 7; i++) { if(i === 4) { results.push(null); } else { var future = today + 86400000 * i; results.push(Counter.getNext(future)); } } console.log(results); var data = { labels: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday","Sunday"], datasets: [ { label: "My Second dataset", fillColor: "rgba(151,187,205,0.2)", strokeColor: "rgba(151,187,205,1)", pointColor: "rgba(151,187,205,1)", pointStrokeColor: "#fff", pointHighlightFill: "#fff", pointHighlightStroke: "rgba(151,187,205,1)", data: results } ] }; var ctx = document.getElementById("myChart").getContext("2d"); var myLineChart = new Chart(ctx).Line(data); 

Is javascript. It creates a counter object, which increases with the request depending on the time of the previous request. Repeatability enters through the third-party seedrandom library, and the chart is drawn using charts.

 <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/seedrandom/2.4.0/seedrandom.min.js"> </script> <body> <canvas id="myChart" width="600" height="400"></canvas> </body> </html> 
0
source

You can use the Unix timestamp. Sort of:

 Downloads = constant + ( unix time / another constant ) 

You can change both constants to get a reasonable number.

PS: That is, if you want a linear function, otherwise you can do:

 Downloads = (unix time) ^ constant 

etc.

-1
source

All Articles