/*
 * Title: genrand.c
 * Author: Jed Marti KI7NNP
 * Description: Generate a random set of values to test.
 * Revision History: (Created Tue Jan 24 10:22:43 2023)
 *   Sun Feb 26 18:11:59 2023 - JBM Add wire size.
 *   Mon Feb 27 07:13:27 2023 - JBM Back to cubics.
 *   Sun Dec  3 11:48:24 2023 - JBM Switch to generic equations.
 */


#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>

#include "equations.h"
#include "indequ.h"

// The range table.
extern range R[];


double genUniform(range *r)
/*     Given a range value, generate a new uniform random distribution number between the limits
 *   at the given resolution. This gets used anywhere we need random values.
 * Parameters:
 *   r: A range data structure set up during initialization or defaults.
 * External References: none
 * Returned values: a new double value.
 * Errors detected: none
 */
{
  return r->low + round(r->vcount * uniform()) * r->major;
}


  
result *genRandResult(void)
/*     Generate a new totally random gene sequence using the range table.
 * Parameters: none
 * External References: none
 * Returned values: a new result structure.
 * Errors detected: none here.
 */
{
  result *r;

  r = newResult();
#define X(nme) r->nme = genUniform(&R[s_##nme]);
  VARS
#undef X
  r->flags = 0xFFFFFFFF;
  
  return r;
}


// EOF
