Total members 11893 |It is currently Fri Nov 08, 2024 11:00 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Hi,

I'm trying to use a simple PRNG C program but am having problems.

Could someone please run this code and let me know if it works and post the output. It should be working perfectly but I am having trouble with my compiler. Thanks


Code:


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

uint16_t rand16();
uint32_t rand32();

uint16_t n, userChosenValue = 0; //Change this for different seed values.
uint16_t numberOfValues = 10; //Change this depending on your needs.
uint32_t seed;
uint32_t mlcg,p,q;
uint64_t tmpseed;

int main(){
  
  
/* Calculate and print a series of 16 bit random numbers */
  seed = (uint32_t)(userChosenValue + 1); 
  
  printf
("16 Bit:\n\n");
  for (n=0;n<numberOfValues;n++){
    printf("%.4x\n",rand16());
  }
  
  
/* Calculate and print a series of 32 bit random numbers */
  seed = (uint32_t)(userChosenValue + 1); 
  
  printf
("\n\n32 Bit:\n\n");
  for (n=0;n<numberOfValues;n++){
    printf("%.8x\t\t\n",rand32());
  }
    
  return 0
;
}

/* Return the next 32 bit random number */
uint32_t rand32() {
    
  tmpseed 
=  (uint64_t)33614U * (uint64_t)seed;
  q = tmpseed;     /* low */
  q = q >> 1;
  p = tmpseed >> 32 ;        /* hi */
  mlcg = p + q;
  if (mlcg & 0x80000000) { 
    mlcg 
= mlcg & 0x7FFFFFFF;
    mlcg++;
  }
  seed = mlcg;
  
  return mlcg
; 
}

/* Return low 16 bits of next 32 bit random number */
uint16_t rand16() {
  return (uint16_t)rand32();
}
 





Author:
Newbie
User avatar Posts: 6
Have thanks: 0 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Pseudo Randon Number Generator code??
 Factor of number using C++ code     -  
 code to find a number all divisors using recursion     -  
 How to write a code for sorting array of 100 number in C++     -  
 convert integer number to octal,hexadecimal number systems     -  
 Histogram Generator     -  
 Calendar Generator     -  
 Sequence Generator JPA     -  
 convert octal number to decimal number     -  
 convert decimal number to octal number     -  
 JPA entity with table generator     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com