Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

82
Vistas
Testing randomness function without intended mean

I have a program that tests a randomness function for how truly random it is:

function testRandom(randomF, tests, intendedMean){
  
  let total = 0;
  
  for(let t = 0; t < tests; t++){
    
    total+=randomF();
    
  }
  
  return Math.abs((total/tests) - intendedMean);
  
}

const randomFunc = () => { return ~~(Math.random() * 2) + 1 }
//returns a randomly choosen 1 or 2.

console.log(testRandom(randomFunc, 100, 1.5));

But is their a way to take out the intended mean and still have a relatively accurate output? My ideas so far are to create a standard deviation set up, but I'm not sure that's the right idea.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I've found the answer. I'm not sure if standard deviation is the correct method, but if it is:

function testRandom(func, tests) {

  let data = [];
  for (let i = 0; i < tests; i++) {
    data.push(func())
  }

  let result = 0;
  const u = data.reduce((a, b) => a + b, 0) / data.length;
  for (let d of data) {
    result += (d - u) ** 2;
  }
  return Math.sqrt(result / data.length + 1) - 1;

}

console.log(testRandom(() => {
  return Math.random()
}, 100));

This will do the job.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda