~ubuntu-branches/ubuntu/lucid/9base/lucid

« back to all changes in this revision

Viewing changes to lib9/nrand.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2006-01-25 15:33:00 UTC
  • Revision ID: james.westby@ubuntu.com-20060125153300-6hh4p9wx8iqqply5
Tags: upstream-2
ImportĀ upstreamĀ versionĀ 2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <lib9.h>
 
2
 
 
3
extern  long    p9lrand(void);
 
4
#define lrand   p9lrand
 
5
#define MASK    0x7fffffffL
 
6
 
 
7
int
 
8
nrand(int n)
 
9
{
 
10
        long slop, v;
 
11
 
 
12
        if(n < 0)
 
13
                return n;
 
14
        slop = MASK % n;
 
15
        do
 
16
                v = lrand();
 
17
        while(v <= slop);
 
18
        return v % n;
 
19
}