Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/trunk/sys/src/libmp/port/mpnrand.c – Rev 26

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
26 7u83 1
#include "os.h"
2
#include <mp.h>
3
#include "dat.h"
4
 
5
/* return uniform random [0..n-1] */
6
mpint*
7
mpnrand(mpint *n, void (*gen)(uchar*, int), mpint *b)
8
{
9
	int bits;
10
 
11
	bits = mpsignif(n);
12
	if(bits == 0)
13
		abort();
14
	if(b == nil){
15
		b = mpnew(bits);
16
		setmalloctag(b, getcallerpc(&n));
17
	}
18
	do {
19
		mprand(bits, gen, b);
20
	} while(mpmagcmp(b, n) >= 0);
21
 
22
	return b;
23
}