GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  PRIMEGEN (3)

NAME

primegen - enumerate small primes

CONTENTS

Syntax
Description

SYNTAX

#include <primegen.h>

void primegen_init(&pg);
uint64 primegen_next(&pg);
uint64 primegen_peek(&pg);
uint64 primegen_count(&pg,bound);
void primegen_skipto(&pg,bound);

struct primegen pg;
uint64 bound;

DESCRIPTION

The primegen library generates prime numbers in order: 2, 3, 5, 7, etc. It can generate primes as large as 10^15.

The simplest way to use primegen is to call primegen_init and then call primegen_next repeatedly. The first call to primegen_next will return 2; the next call will return 3; the next call will return 5; and so on.

At each moment the next few primes to be returned by primegen_next are buffered inside pg. primegen_init initializes pg with the first few primes, starting at 2. You must initialize pg with primegen_init before using pg with any of the other primegen routines. You may call primegen_init again to start over at 2.

primegen_next returns the next buffered prime and removes that prime from pg. primegen_peek returns the next buffered prime but does not change pg.

primegen_skipto discards all primes up to bound. It has the same effect as

while (primegen_peek(&pg) < bound)
primegen_next(&pg);

primegen_count discards all primes up to bound and returns the number of primes discarded.

You can set up several independent generators; all primegen data is stored in pg. Beware, however, that each struct primegen uses quite a bit of memory.

SEE ALSO

primes(1), primespeed(1)
Search for    or go to Top of page |  Section 3 |  Main Index


PRIMEGEN (3) -->

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.