亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? randtest.c

?? 隨機數算法
?? C
字號:
/* randtest.c : Defines the entry point for the console application.
//
//
//	RANDTEST is a command-line program.  It is designed so that it can be executed
//	from a batch file.  It requires the name of an input file and the word size
//	(in bits) to be used during the analysis.  If the input file is supplied on the
//	command line, it must be the first argument.  If not, it will be requested.
//	The word size may be specified on the command line using the -wNN option.
//	If it is not specified, it will be requested.
/*
	This file originally written by John Hadstate  
	Modified by Mike Rosing on and after October 19, 2001
		added fixed ram for data block and a subroutine to 
		access it as binary.
		added -x option for binary input file (for rank test)

		added -r option for binary matrix rank test (Nov 10, 2001)
		added -m option for monobits frequency test (Nov 14, 2001)
                added -l option for longest run of ones test (Jan 2, 2002)
                      This includes bigfloat package for computing probability
		      tables to high accuracy for low runs.
*/
#include "randtest.h"
#include "bigfloat.h"

#define MAXRAMSIZE 16*1024*1024

int nByteMask[BITS_PER_BYTE] =
{
	0x00000001, 0x00000002, 0x00000004, 0x00000008,
	0x00000010, 0x00000020, 0x00000040, 0x00000080
};

unsigned char rawbits[MAXRAMSIZE];

int main(int argc, char* argv[])
{
	FILE		*fpInput = NULL;

	int			nBitNumber = (-1),
				nWordSize = (-1);
	int 		i;
	char		*pc = NULL;
	char		strOptions[1024];
	char		strInputFile[1024];

	bool		bAnalyzeAllBits = false;
	bool		bNumericAnalysis = false;
	bool            dorank = false;
	bool            domono = false;
	bool            dofreq = false;
	bool            doruns = false;
	bool            dolongs = false;

	int		nBytes;
	SRCPTR	        bitBlockltl, bitBlockbig;
	int		rankvalue, ii, rankstart;
	int             error;
	double          chi, pvalue;
	int             monowidth;
	int             numPs, numBlocks;
	int             longRunBlocks, tblsz;

	CHIENTRY       ctbl[21];
	FLOAT          test;

/*  initialize floating point package  */

	init_float();

/*	BuildChiTable( 8, ctbl);
	printf("M = 8\n");
	for( i=0; i<8; i++)
	  printf("ctbl[%d].class = %d  .prob = %e\n",i, ctbl[i].class, ctbl[i].prob);
	printf("\n");

	printf("M = 128\n");
	BuildChiTable( 128, ctbl);
	i = 0;
	for( i=0; i<21; i++)
	  printf("ctbl[%d].class = %d  .prob = %e\n",i, ctbl[i].class, ctbl[i].prob);
	printf("\n");
/*
	BuildChiTable( 512, ctbl);
	for( i=0; i<21; i++)
	  printf("ctbl[%d].class = %d  .prob = %e\n",i, ctbl[i].class, ctbl[i].prob);

	exit(0);       
/*
	First, concatenate all the command-line options that are
	prefixed with a '-' and convert them to lower case.
	We are pretty sure these cannot be the Input File name
	and, in any case, the Input File name may not start with
	a '-' (our restriction).
*/
	strOptions[0] = NUL;

	for (i = 1; i < argc; i++)
	{
		if (*argv[i] == '-') SAFECAT(strOptions, argv[i]);
	}

	for (i = 0; strOptions[i] != 0; i++) strOptions[i] = tolower(strOptions[i]);
/*
	Now go find the first command-line option that does not begin with
	a '-'.  Accept this as the Input File name.
*/
	strInputFile[0] = NUL;

	for (i = 1; i < argc; i++)
	{
		if (*argv[i] != '-')
		{
//			SAFECOPY(strInputFile, argv[1]);  I think this is a bug!! (MGR)
			SAFECOPY(strInputFile, argv[i]);
			break;
		}
	}
/*
	If the Input File name has not been specified, we've got to
	prompt for it interactively.  We're going to read from stdin
	to allow one last bit of hacking: stdin could be redirected to
	a file containing the Input File name and other required
	parameters.
*/

	if (strInputFile[0] == NUL)
	{
		fputs("\nName of input file: ", stdout);
		fscanf(stdin, " %1023s", strInputFile);
	}
/*
	If the word size of the random number stream has not been specified,
	we've got to prompt for it interactively.
*/
	if ((pc = strstr(strOptions, "-w")) == NULL)
	{
		fputs("\nWord size (in bits): ", stdout);
		fscanf(stdin, " %d", &nWordSize);
	}
	else
	{
		if (sscanf(pc, " -w%d", &nWordSize) != 1)
		{
			fprintf(stdout, "\n-w Option Specification Invalid: %s\n", pc);

			return (1);
		}
	}
/*
	If there are no command line options specified,
	we need to prompt for numeric or bitwise analysis.
*/
	if (strOptions[0] == NUL)
	{
		char		cTemp;

		fputs("\nNumeric (n) or Bitwise (b) analysis? ", stdout);
		fscanf(stdin, " %c", &cTemp);
		cTemp = tolower(cTemp);

		if (cTemp == 'n')
		{
			SAFECOPY(strOptions, "-n");
		}
		else if (cTemp == 'b')
		{

			fputs("\nWhich bit (-1 for ALL): ", stdout);
			fscanf(stdin, " %d", &nBitNumber);

			if (nBitNumber >= 0)
			{
				sprintf(strOptions, "-b%d", nBitNumber);
			}
		}
	}
/*
	If the -n option is specified, we don't need the -b option.  If the
	-b option is needed but not specified, it means run the analysis once
	on each bit in the word.
*/
	if ((pc = strstr(strOptions, "-n")) != NULL)
	{
		if ((pc = strstr(strOptions, "-b")) != NULL)
		{
			fprintf(stdout, "\n-n Option conflicts with -b Option: %s\n", strOptions);

			return (1);
		}

		bNumericAnalysis = true;
	}
	else
	{
		bNumericAnalysis = false;
	/*
		If the bit number in the words of the random number stream has not been specified,
		we assume that they want to analyze all bits.
	*/
		if ((pc = strstr(strOptions, "-b")) != NULL)
		{
			if (sscanf(pc, " -b%d", &nBitNumber) != 1)
			{
				fprintf(stdout, "\n-b Option Specification Invalid: %s\n", pc);

				return (1);
			}

			bAnalyzeAllBits = false;
		}
		else
		{
			bAnalyzeAllBits = true;
		}
	}
/*
	Word Size must be greater than 0 bits.  For numeric analysis, word size
	must be less than or equal to 32 bits.
*/
	if ((nWordSize <= 0) || (bNumericAnalysis && (32 < nWordSize)))
	{
		fprintf(stdout, "\n-w Option Size Invalid: %d\n", nWordSize);

		return (1);
	}
/*
	If Bit Number is required, it must be between 0 and (N-1) where N
	is the number of bits in a word.
*/
	if (!bNumericAnalysis && !bAnalyzeAllBits)
	{
		if ((nBitNumber < 0) || (nWordSize <= nBitNumber))
		{
			fprintf(stdout, "\n-b Option Bit Number Invalid: %d\n", nBitNumber);

			return (1);
		}
	}

	if ((fpInput = fopen(strInputFile, "r")) == NULL)
	{
		char	strErrorMessage[1024];

		sprintf(strErrorMessage, "\nUnable to open %s", strInputFile);
		perror(strErrorMessage);

		return (2);
	}

/*  Read up to max buffer size of data.  We can loop on this if file is
	bigger, or increase buffer size.  Ram is cheap nowadays!!
*/
	if( ( pc = strstr( strOptions, "-x") ) != NULL)
	{
		nBytes = fread( rawbits, 1, MAXRAMSIZE, fpInput);
		bitBlockltl.byteptr = rawbits;
		bitBlockltl.bitpos = 0;  // little endian, least significant bit
		bitBlockbig.byteptr = rawbits;
		bitBlockbig.bitpos = 7;  // big endian, most significant bit
	}

/*  if rank test specified, get starting matrix dimension.
    Test loops over data block going from starting dimension up to
    maximum word size.
*/
	if( (pc = strstr( strOptions, "-r") ) != NULL)
	{
	  if (sscanf(pc, " -r%d", &rankstart) != 1) 
	  {
	    fprintf(stdout, "\ninvalid parameter for rank matrix probabilities\n");
	    return(3);
	  }
	  dorank = true;
	}

/*  if monobits test specified, get number of bits in block to test.
    does as many blocks as possible with raw data.
*/
	if( (pc = strstr( strOptions, "-m") ) != NULL)
	{
	  if (sscanf(pc, " -m%d", &monowidth) != 1) 
	  {
	    fprintf(stdout, "\ninvalid parameter for monobits frequency test\n");
	    return(4);
	  }
	  domono = true;
	}

/*  if frequency test specified, get number of p-values to generate.
    does as many blocks as possible with raw data, assuming that nWordSize
    is bits per block.  Number of bits is assumed to be 8*nBytes, so number
    of bits to work with is 8*nBytes/(number of p-values)(=N in NIST docs)
    and number of trials within that is determined by nWordSize (=M in 
    NIST docs).
*/
	if( (pc = strstr( strOptions, "-f") ) != NULL)
	{
	  if (sscanf(pc, " -f%d", &numPs) != 1) 
	  {
	    fprintf(stdout, "\ninvalid parameter for frequency test within a block\n");
	    return(4);
	  }
	  dofreq = true;
	}

/*  if runs test specified, get number of p-values to generate.
    Does as many blocks as possible assuming number of bits is 8*nBytes.
*/
	if( (pc = strstr( strOptions, "-u") ) != NULL)
	{
	  if (sscanf(pc, " -u%d", &numPs) != 1) 
	  {
	    fprintf(stdout, "\ninvalid parameter for frequency test within a block\n");
	    return(4);
	  }
	  doruns = true;
	}

/*  if longest runs test specified, get number of p-values to generate.
    Does as many blocks as possible assuming number of bits is 8*nBytes.
*/
	if( (pc = strstr( strOptions, "-l") ) != NULL)
	{
	  if (sscanf(pc, " -l%d", &longRunBlocks) != 1) 
	  {
	    fprintf(stdout, "\ninvalid parameter for frequency test within a block\n");
	    return(5);
	  }
	  dolongs = true;
	}

// need to merge both methods.  Rank test assumes binary data already
// internal.  compare running times and simplicity, but merge both methods.		

	if (bNumericAnalysis)
	{
	//	AnalyzeNumeric(fpInput, nWordSize);
	}
	else
	{
	  if (bAnalyzeAllBits)
	  {
	    if (dorank)
	    {
	      for (ii = rankstart; ii <= nWordSize; ii++)
	      {
		
/*  test matrix rank code  */

		printf("\ndimension = %d\n", ii);
		error = ranktest( bitBlockltl, LITTLENDIAN, ii, 8*nBytes/ii/ii,
				  &chi, &pvalue);
		if( error < 0) printf("Error computing little endian binary rank test.\n");
		else printf("Little endian chi^2 = %f,  p-value = %f\n", chi, pvalue);
		error = ranktest( bitBlockbig, BIGENDIAN, ii, 8*nBytes/ii/ii,
				  &chi, &pvalue);
		if( error < 0) printf("Error computing big endian binary rank test.\n");
		else printf("Big endian chi^2 = %f,  p-value = %f\n", chi, pvalue);
	      }
	    }
	    if (domono)
	    {
	      ii = nBytes*8/monowidth;
	      for( i=0; i<ii; i++)
	      {
		chi = monobits( &bitBlockltl, monowidth);
		printf("block %d gives p-value %f\n", i, chi);
	      }
	    }
	    if (dofreq)
	    {
      /* reset source pointers */

	      bitBlockltl.byteptr = rawbits;
	      bitBlockltl.bitpos = 0;  // little endian, least significant bit
	      bitBlockbig.byteptr = rawbits;
	      bitBlockbig.bitpos = 7;  // big endian, most significant bit
	      numBlocks = 8*nBytes/numPs/nWordSize;
	      printf("numblocks = %d\n", numBlocks);
	      for( i=0; i<numPs; i++)
	      {
		chi = freqtest( &bitBlockltl, LITTLENDIAN, nWordSize, numBlocks);
		pvalue = chisqr( chi, numBlocks);
		printf("frequency test little endian chi^2 = %f, p-value = %f\n", 
		       chi, pvalue);
		chi = freqtest( &bitBlockbig, BIGENDIAN, nWordSize, numBlocks);
		pvalue = chisqr( chi, numBlocks);
		printf("frequency test big endian chi^2 = %f, p-value = %f\n", 
		       chi, pvalue);
	      }
	    }
	    if( doruns)
	    {
	      bitBlockltl.byteptr = rawbits;
	      bitBlockltl.bitpos = 0;  // little endian, least significant bit
	      bitBlockbig.byteptr = rawbits;
	      bitBlockbig.bitpos = 7;  // big endian, most significant bit
	      numBlocks = 8*nBytes/numPs;
	      printf("number of bits = %d\n", numBlocks);
	      for( i=0; i<numPs; i++)
	      {
		pvalue = runs( &bitBlockltl, LITTLENDIAN, numBlocks );
		printf("runs test little endian p-value = %f\n",  pvalue);
		pvalue = runs( &bitBlockbig, BIGENDIAN, numBlocks);
		printf("runs test big endian p-value = %f\n", pvalue);
	      }
	    }
	    if( dolongs)
	    {
	      bitBlockltl.byteptr = rawbits;
	      bitBlockltl.bitpos = 0;  // little endian, least significant bit
	      bitBlockbig.byteptr = rawbits;
	      bitBlockbig.bitpos = 7;  // big endian, most significant bit
	      printf("WARNING: large block sizes may take a very long time to simply\n");
	      printf("         compute the probability table!\n");
	      printf("  Building table for %d blocksize... ", nWordSize);
	      BuildChiTable( nWordSize, ctbl );
	      printf("\n");
	      if( nWordSize < 21) tblsz = nWordSize;
	      else tblsz = 21;
	      pvalue = longrun( &bitBlockltl, LITTLENDIAN, nWordSize, longRunBlocks, 
		ctbl, tblsz);
	      printf("Little endian p-value = %f\n", pvalue);
	      pvalue = longrun( &bitBlockbig, BIGENDIAN, nWordSize, longRunBlocks,
				ctbl, tblsz);
	      printf("Big endian p-value = %f\n", pvalue);
	    }
	    else
	    {
//		AnalyzeBitStream(fpInput, nWordSize, ii);
	    }
	  }
	  else
	  {
	    //	AnalyzeBitStream(fpInput, nWordSize, nBitNumber);
	  }
	}

	fclose(fpInput);
	
	return 0;
}
/*

  int FillBitStreamBuffer(BITSTREAM *bp)

  This function reads a pair of hex digits from the input data stream
  into a byte buffer.

  Function Returns:

  0 == Success.
  Anything else, some kind of I/O or data error

*/
int	FillBitStreamBuffer(BITSTREAM *bp)
{
	if (bp->nError == 0)
	{
		int		nFileChar;

		if (fscanf(bp->fp, " %2x", &nFileChar) == 1)
		{
			bp->ucByteBuf = (unsigned char) nFileChar;
		}
		else if ((bp->nError = ferror(bp->fp)) == 0)
		{
			bp->nError = (-1);
		}
	}

	return bp->nError;
}
/*

  int ResetBitStream(BITSTREAM *bp)

  This function resets the file pointer to the beginning
  of the file, reads the first byte into a buffer and

  Function returns:

  0 == Success
  Anything else, some kind of I/O error.

*/

int ResetBitStream(BITSTREAM *bp)
{
	if (bp->fp != NULL)
	{
		bp->nError = fseek(bp->fp, 0L, SEEK_SET);

		if (bp->nError == 0)
		{
			FillBitStreamBuffer(bp);
		}

		bp->nPrevBit = bp->nBitNumber - bp->nWordSize;
	}
	else
	{
		bp->nError = (-1);
	}

	return bp->nError;
}

/*

  int InitBitStream(BITSTREAM *bp, FILE *fp, int nWordSize)

  This function initializes a BITSTREAM object.

  Function returns:

  0 == Success
  Anything else, some kind of I/O error.

*/

int	InitBitStream(BITSTREAM *bp, FILE *fp, int nWordSize, int nBitNumber)
{
	bp->fp = fp;
	bp->nBitNumber = nBitNumber;
	bp->nWordSize = nWordSize;

	return ResetBitStream(bp);
}

/*

  int GetNextBit(BITSTREAM *bp)

  The function returns the next bit in a stream of bits
  from the specified input file.

  Function Returns:

  0  == The bit is zero
  1  == The bit is one
  -1 == Some kind of I/O or data error

*/

int GetNextBit(BITSTREAM *bp)
{
	int		nRet = (-1);

	if (bp->fp != NULL)
	{
		if (bp->nError == 0)
		{
			int		nBitNum = bp->nPrevBit + bp->nWordSize;
			int		nSkipBytes = nBitNum / BITS_PER_BYTE;
			int		nNextBit = nBitNum % BITS_PER_BYTE;

			while ((nSkipBytes > 0) && (bp->nError == 0))
			{
				if (FillBitStreamBuffer(bp) == 0)
				{
					nSkipBytes -= 1;
				}
			}

			if (bp->nError == 0)
			{
				nRet = (((int) bp->ucByteBuf & nByteMask[nNextBit]) == 0) ? 0 : 1;
				bp->nPrevBit = nNextBit;
			}
		}
	}

	return nRet;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品国产伦一区二区三区观看体验| 国内国产精品久久| 99精品视频在线播放观看| 免费在线视频一区| 亚洲欧美综合色| 亚洲国产一区在线观看| 国产精品毛片大码女人| 精品婷婷伊人一区三区三| 国产老妇另类xxxxx| 国产精品女主播在线观看| 精品伦理精品一区| 欧美一区二区三区的| 国产999精品久久| 国产成人免费在线观看| 日本女人一区二区三区| 亚洲福利视频一区| 国产一区 二区| 国产一区免费电影| 精品夜夜嗨av一区二区三区| 亚洲国产欧美在线人成| 亚洲伦理在线精品| 欧美日韩亚洲综合在线 欧美亚洲特黄一级 | 中文字幕免费不卡| 麻豆国产精品视频| 久久精品人人做| 色999日韩国产欧美一区二区| 爽好久久久欧美精品| 久久精品水蜜桃av综合天堂| www.av精品| 蜜臀久久99精品久久久久久9| 欧美激情一区二区| 欧美巨大另类极品videosbest| 国内成人自拍视频| 一区二区三区高清在线| 亚洲精品在线观| 日本福利一区二区| 国产一区二区在线视频| 亚洲小少妇裸体bbw| 国产色婷婷亚洲99精品小说| 在线国产电影不卡| 国产成人aaa| 日产欧产美韩系列久久99| 国产精品国产三级国产普通话99| 欧美日韩大陆一区二区| 国产一区二区三区精品视频| 亚洲成人动漫精品| 国产精品免费视频观看| 日韩欧美自拍偷拍| 欧美性受xxxx黑人xyx| 国产黄色成人av| 欧美aaaaaa午夜精品| 亚洲男人电影天堂| 中文字幕欧美区| 欧美电视剧在线观看完整版| 在线观看一区不卡| 成人午夜在线免费| 精品一区二区三区免费播放| 亚洲妇女屁股眼交7| 亚洲图片另类小说| 久久久久久久久久久电影| 欧美一区二区黄| 欧美亚洲高清一区| 色悠久久久久综合欧美99| 国产99久久久国产精品潘金网站| 九九九久久久精品| 免费在线看成人av| 视频在线观看一区| 亚洲v日本v欧美v久久精品| 亚洲欧美aⅴ...| 一区精品在线播放| 中文字幕在线观看一区二区| 国产精品国产三级国产| 中文字幕欧美激情| 中文字幕一区二区三区av| 久久久久久夜精品精品免费| 欧美不卡一二三| 久久综合五月天婷婷伊人| 精品国产免费一区二区三区四区| 欧美一二三区精品| 日韩一区二区在线观看| 日韩精品最新网址| 久久综合色鬼综合色| 精品三级av在线| 久久午夜羞羞影院免费观看| 久久天天做天天爱综合色| 国产欧美一区二区在线观看| 亚洲国产成人私人影院tom| 国产精品久久久久久久久免费相片 | 偷拍日韩校园综合在线| 五月激情六月综合| 久久精品噜噜噜成人av农村| 久久99精品久久久久久国产越南 | 在线播放亚洲一区| 日韩免费视频一区| 国产亚洲精品aa午夜观看| 国产午夜一区二区三区| 国产精品免费看片| 亚洲综合成人在线| 日韩 欧美一区二区三区| 国产麻豆成人精品| 成人av免费观看| 欧美日韩中文字幕精品| 日韩欧美一区在线| 久久精子c满五个校花| 成人欧美一区二区三区小说| 亚洲成a人片在线不卡一二三区 | 国产精品一区二区免费不卡 | 久久久午夜电影| 亚洲日本乱码在线观看| 亚洲国产精品麻豆| 久久精品99国产精品日本| 成人一区二区三区中文字幕| 欧美性淫爽ww久久久久无| www国产精品av| 一二三区精品福利视频| 麻豆视频一区二区| 99国产欧美久久久精品| 欧美日韩一卡二卡三卡 | 日韩视频在线你懂得| 国产免费成人在线视频| 亚洲一二三区视频在线观看| 久久激情五月激情| 色域天天综合网| 精品99一区二区三区| 亚洲最新视频在线观看| 国产一区二区调教| 日本丶国产丶欧美色综合| 日韩欧美卡一卡二| 亚洲一区在线观看免费 | 亚洲人成人一区二区在线观看| 视频一区二区不卡| 色诱亚洲精品久久久久久| 精品处破学生在线二十三| 亚洲已满18点击进入久久| 国产自产高清不卡| 欧美日韩一区二区三区免费看| 欧美激情一区二区三区不卡 | 欧美日韩高清一区| 中文字幕一区二区三区视频| 久久成人av少妇免费| 欧美性感一类影片在线播放| 国产精品家庭影院| 激情综合网最新| 欧美精品日韩综合在线| 亚洲欧美日韩国产综合在线| 国产一区二区网址| 日韩欧美一级在线播放| 性做久久久久久| 欧洲视频一区二区| 中文字幕国产一区| 国产成人日日夜夜| 精品国产免费视频| 麻豆传媒一区二区三区| 欧美日韩高清一区| 亚洲电影一区二区三区| 欧美影片第一页| 亚洲激情图片一区| 99在线精品观看| 国产精品白丝在线| www.亚洲人| 亚洲欧洲成人自拍| 波多野结衣中文字幕一区| 欧美激情在线一区二区| 国产精品亚洲综合一区在线观看| 欧美变态口味重另类| 人人超碰91尤物精品国产| 91精选在线观看| 日韩高清在线电影| 欧美一区二区三区在线视频| 首页国产欧美久久| 日韩欧美在线不卡| 黑人精品欧美一区二区蜜桃| 337p日本欧洲亚洲大胆精品 | 成人免费毛片高清视频| 欧美激情中文不卡| 99热这里都是精品| 亚洲日本护士毛茸茸| 欧美图区在线视频| 日韩中文欧美在线| 欧美刺激午夜性久久久久久久| 捆绑变态av一区二区三区| 久久老女人爱爱| 99久久久久久| 亚洲一区视频在线| 制服丝袜日韩国产| 韩国一区二区三区| 中文字幕av资源一区| 一本大道av伊人久久综合| 亚洲一区二区三区四区的| 337p亚洲精品色噜噜| 久久国产生活片100| 日本一区二区视频在线| 91在线观看高清| 久久99精品国产.久久久久久| 久久尤物电影视频在线观看| www.欧美亚洲| 亚洲国产另类av| 精品久久久久av影院| 成人动漫一区二区三区| 一个色综合av|