jeudi 12 août 2021

Picking integer numbers over discret intervals with c++

Given a set of N integers numbers (all having 1 unit distance from each other) I would like to create a vector using each of those number T times each.

Lets say X= [1,2,...,N] is my set of numbers and I want to create a vector of T.N size such that each x in X appears $T$ times each (the order do not matter).

My idea is the following:

Using a original library of c++ I pick a random number from X and save the amount of times this number was pick, after some x be chosen T times I break the set X in two parts, say X1=[1,2,...,x) and X2=(x,...,N]. Therefore, in order to randomly take the next number I generate a uniform (0,1) number before, if it is bigger than 1/2 I pick the new number over X2 and from X1 otherwise.

Keeping on like this, lets say there are now K numbers which where pick T times already. I will pick the next number from one of the K+1 sets generated by removing these selected values. In order to pick some of these intervals I again generate a (0,1) number and ''break'' the (0,1) interval over K+1 equal parts of length (1/K+1) and pick the next set accordingly.

Does that makes sense?




Aucun commentaire:

Enregistrer un commentaire