Routine bas-niveau
fr - eng


geninti_c - routine de calcul générateur de nombre entier aléatoire (version nombre entier)

Module

Paramètres

Contenu du fichier


/* geninti_c subroutine
 * Random Integer Number Generator
 * IRCOM GROUP - Author : A.Layec
 *
 * Copyright (C) 2007 Alan Layec
 *
 * This file is part of modnumlib.
 *
 * modnumlib is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * modnumlib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with modnumlib; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

/* REVISION HISTORY :
 * $Log$
 */

#include <stdlib.h>

#include "modnum_lib.h"

/* geninti_c routine de calcul de mots entiers aléatoires
 *
 * Entrées :
 *  n     : dimension 1 de la matrice de sortie (scalaire)
 *  m     : dimension 2 de la matrice de sortie (scalaire)
 *  nbit  : longueur des mots binaires des éléments du vecteur de sorties (scalaire)
 *  typ   : type des générateurs binaires (scalaire)
 *          0 : génére 1 seul bit codé NRZ
 *          1 : génère 1 seul bit codé RZ, ou un mot non signé
 *          2 : génère un mot codé code complément à 2
 *
 * Sorties :
 *  y : pointeur sur entier de sortie
 *
 * dépendances
 * math.h
 */

void geninti_c(int *n,int *m,int *nbit,int *typ,int *y)
{
 /*déclaration des variables compteurs*/
 int i,j,k,l;

 switch (*typ)
 {
   /*Type 0 -> dédié signal NRZ*/
   case 0 :
   {
    for(l=0;l<(*m);l++) {
      for(i=0;i<(*n);i++) {
        y[l*(*n)+i] = ((rand()&1)*2-1);
      }
    }
    break;
   }

   /*Type 1 -> mot non signé*/
   case 1 :
   {
    k = 1;
    k = k<<(*nbit);
    for(l=0;l<(*m);l++) {
      for(i=0;i<(*n);i++) {
        j = rand();
        y[l*(*n)+i] = (j&(k-1));
      }
    }
    break;
   }

   /*Type 2 -> mot codé code complémént à 2*/
   case 2 :
   {
    for(l=0;l<(*m);l++) {
      for(i=0;i<(*n);i++) {
        j  = rand();
        j -= 2<<((*nbit)-2);
        j &= (2<<((*nbit)-1)) - 1;
        j -= 2<<((*nbit)-2);
        y[l*(*n)+i] = j;
      }
    }
   }
   break;
 }
 return;
}

Auteurs

INRIA A. Layec