Generation of uniformly distributed random numbers (0,1)

 

Generation of uniformly distributed random numbers (0,1) by MQL tools without external *.dll?

 
int MathRand()
The function returns a pseudorandom integer in the range 0 to 32767. Before you call this function for the first time, you must use MathSrand to set the pseudorandom number generator to initial state.
Example:
  MathSrand(TimeLocal());
// Displays 10 numbers.
for(int i=0;i<10;i++ )
Print("random value ", MathRand());
 
sergeev >>:
int MathRand()
Функция возвращает псевдослучайное целое число в дипазоне от 0 до 32767. Перед первым вызовом функции необходимо использовать функцию MathSrand, чтобы перевести генератор псевдослучайных чисел в начальное состояние.
Пример:


I know that!

I'm asking about the range (0.1).

 

Comrade asks for 0 and 1 evenly distributed, so split them into even and odd.

MathSrand(TimeLocal());
  // Отображает 10 чисел.
  for(int i=0; i<10; i++ )
     Print("произвольная величина ", MathMod(MathRand(),2));

like this.

 
Urain писал(а) >>

Comrade asks for 0 and 1 evenly distributed, so split them into even and odd.

Like this.

Or do you mean real numbers in a given range. Then like this:

MathRand() / 32767.0
 

I'm sorry, if you're looking for a range.

MathSrand(TimeLocal());
  // Отображает 10 чисел.
  for(int i=0; i<10; i++ )
     Print("произвольная величина ", MathRand()/32768);

something like this.

 
lea >>:

Или имеются ввиду вещественные числа в заданном диапазоне. Тогда так:


There, there.

MathSrand(TimeLocal());
  // Отображает 10 чисел.
  for(int i=0; i<10; i++ )
     Print("произвольная величина ", MathRand()/32768);
It's weak.
 
gumgum >>:

Вот, вот.

Слабовато. помощнее?
MathSrand(TimeLocal());
...............
...............
...............
//---------------------------Непрерывный Генератор СЧ---------------------
double CRG(double min,double max) { return(min+((max-min)*MathRand()/32767.0));}
//=======================================================================

where:

min - range start

max - end of range.


In your case it will be:

void Start()
{
MathSrand(TimeLocal());
...............
...............
...............
double p=CRG(0.0,1.0);
}

//---------------------------Непрерывный Генератор СЧ---------------------
double CRG(double min,double max) { return(min+((max-min)*MathRand()/32767.0));}
//=======================================================================
 

if so,

double ran= MathRand()/32768.;
then between n/32768. and n+1/32768. at n e Z & n e [0.32767] is empty. This is not good.


 
joo >>:

где:

min - начало диапазона

max - конец диапазона.


В Вашем случае будет:


==
MathRand()/32768.
:(
 
gumgum писал(а) >>

if so,

then between n/32768. and n+1/32768. with n e Z & n e [0.32767] is empty. This is not good.

Do you know, dear fellow, that there is an infinite number of real numbers between any real numbers, however close to each other?

And do you know that the interval (0,1) is equivalent to an infinite line in power?

If no - think about it.

If yes - formulate your question correctly.

At the same time try to say at what density (pieces per unit length) do you want to have a MF generation ?

Or maybe you want your GSF to generate all numbers a segment of (0,1) ?

Reason: