Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

RandomPermutation Class Reference

#include <newran.h>

Inheritance diagram for RandomPermutation:

Inheritance graph
[legend]
Collaboration diagram for RandomPermutation:

Collaboration graph
[legend]

Public Member Functions

void Next (int N, int M, int p[], int start=0)
void Next (int N, int p[], int start=0)

Private Attributes

Random U

Member Function Documentation

void RandomPermutation::Next int  N,
int  p[],
int  start = 0
[inline]
 

Reimplemented in RandomCombination.

Definition at line 656 of file newran.h.

00656 { Next(N, N, p, start); }

void RandomPermutation::Next int  N,
int  M,
int  p[],
int  start = 0
 

Reimplemented in RandomCombination.

Definition at line 927 of file newran.cpp.

References ErrorNoSpace(), Ars::Graf::M, Random::Next(), and U.

Referenced by RandomCombination::Next(), and test4().

00928 {
00929    // N = size of urn; M = number of draws
00930    if (N < M) Throw(Logic_error("Newran: N < M in RandomPermutation"));
00931    int i;
00932    int* q = new int [N];
00933    if (!q) ErrorNoSpace();
00934    for (i = 0; i < N; i++) q[i] = start + i;
00935    for (i = 0; i < M; i++)
00936    {
00937       int k = i + (int)(U.Next() * (N - i));       // uniform on i ... N-1
00938       p[i] = q[k]; q[k] = q[i];                    // swap i and k terms
00939                                                    // but put i-th term into p
00940    }
00941    delete [] q;
00942 }


Field Documentation

Random RandomPermutation::U [private]
 

Definition at line 649 of file newran.h.

Referenced by Next().


The documentation for this class was generated from the following files:
Generated on Fri Dec 5 04:06:34 2003 for Borqueror by doxygen 1.3.3