Skip to content

Commit f152586

Browse files
committed
Add Typescript definition
1 parent fa2672f commit f152586

File tree

3 files changed

+497
-0
lines changed

3 files changed

+497
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 2.0
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import * as random from '@stdlib/types/random';
24+
25+
/**
26+
* Interface defining `factory` options.
27+
*/
28+
interface Options {
29+
/**
30+
* Pseudorandom number generator which generates uniformly distributed pseudorandom numbers.
31+
*/
32+
prng?: random.PRNG;
33+
34+
/**
35+
* Pseudorandom number generator seed.
36+
*/
37+
seed?: random.PRNGSeedMT19937;
38+
39+
/**
40+
* Pseudorandom number generator state.
41+
*/
42+
state?: random.PRNGStateMT19937;
43+
44+
/**
45+
* Specifies whether to copy a provided pseudorandom number generator state.
46+
*/
47+
copy?: boolean;
48+
}
49+
50+
/**
51+
* Interface for PRNG properties and methods.
52+
*/
53+
interface PRNG {
54+
/**
55+
* Generator name.
56+
*/
57+
readonly NAME: string;
58+
59+
/**
60+
* Underlying pseudorandom number generator.
61+
*/
62+
readonly PRNG: random.PRNG;
63+
64+
/**
65+
* PRNG seed.
66+
*/
67+
readonly seed: random.PRNGSeedMT19937;
68+
69+
/**
70+
* PRNG seed length.
71+
*/
72+
readonly seedLength: number;
73+
74+
/**
75+
* PRNG state.
76+
*/
77+
state: random.PRNGStateMT19937;
78+
79+
/**
80+
* PRNG state length.
81+
*/
82+
readonly stateLength: number;
83+
84+
/**
85+
* PRNG state size (in bytes).
86+
*/
87+
readonly byteLength: number;
88+
89+
/**
90+
* Serializes the pseudorandom number generator as a JSON object.
91+
*
92+
* @returns JSON representation
93+
*/
94+
toJSON(): string;
95+
}
96+
97+
/**
98+
* Interface for generating pseudorandom numbers from a hypergeometric distribution with pre-specified parameter values.
99+
*/
100+
interface NullaryFunction extends PRNG {
101+
/**
102+
* Returns a pseudorandom number drawn from a hypergeometric distribution.
103+
*
104+
* @returns pseudorandom number
105+
*/
106+
(): number;
107+
}
108+
109+
/**
110+
* Interface for generating pseudorandom numbers from a hypergeometric distribution without pre-specified parameter values.
111+
*/
112+
interface BinaryFunction extends PRNG {
113+
/**
114+
* Returns a pseudorandom number drawn from a hypergeometric distribution.
115+
*
116+
* @param N - population size
117+
* @param K - subpopulation size
118+
* @param n - number of draws
119+
* @returns pseudorandom number
120+
*/
121+
( N: number, K: number, n: number ): number;
122+
}
123+
124+
/**
125+
* Interface for generating pseudorandom numbers drawn from a hypergeometric distribution.
126+
*/
127+
interface Random extends PRNG {
128+
/**
129+
* Returns pseudorandom number drawn from a hypergeometric distribution.
130+
*
131+
* ## Notes
132+
*
133+
* - `N`, `K`, and `n` must all be nonnegative integers; otherwise, the function returns `NaN`.
134+
* - If `n > N` or `K > N`, the function returns `NaN`.
135+
*
136+
* @param N - population size
137+
* @param K - subpopulation size
138+
* @param n - number of draws
139+
* @returns pseudorandom number
140+
*
141+
* @example
142+
* var v = hypergeometric( 10, 5, 7 );
143+
* // returns <number>
144+
*
145+
* @example
146+
* var v = hypergeometric( 5, 3, 2 );
147+
* // returns NaN
148+
*/
149+
( N: number, K: number, n: number ): number;
150+
151+
/**
152+
* Returns a pseudorandom number generator for generating random numbers from a hypergeometric distribution.
153+
*
154+
* ## Notes
155+
*
156+
* - When provided `N`, `K`, and `n`, the returned PRNG returns random variates drawn from the specified distribution.
157+
*
158+
* @param N - population size
159+
* @param K - subpopulation size
160+
* @param n - number of draws
161+
* @param options - function options
162+
* @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers
163+
* @param options.seed - pseudorandom number generator seed
164+
* @param options.state - pseudorandom number generator state
165+
* @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true)
166+
* @throws `N` must be a nonnegative integer
167+
* @throws `K` must be a nonnegative integer
168+
* @throws `n` must be a nonnegative integer
169+
* @throws `n` must be less than or equal to `N`
170+
* @throws `K` must be less than or equal to `N`
171+
* @throws must provide a valid state
172+
* @returns pseudorandom number generator
173+
*
174+
* @example
175+
* var rand = hypergeometric.factory( 10, 5, 7 );
176+
* var v = rand();
177+
* // returns <number>
178+
*
179+
* @example
180+
* var rand = hypergeometric.factory( 5, 3, 2, {
181+
* 'seed': 297
182+
* });
183+
* var v = rand();
184+
* // returns <number>
185+
*/
186+
factory( N: number, K: number, n: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length
187+
188+
/**
189+
* Returns a pseudorandom number generator for generating random numbers from a hypergeometric distribution.
190+
*
191+
* ## Notes
192+
*
193+
* - When not provided `N`, `K`, and `n`, the returned PRNG requires that `N`, `K`, and `n` be provided at each invocation.
194+
*
195+
* @param options - function options
196+
* @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers
197+
* @param options.seed - pseudorandom number generator seed
198+
* @param options.state - pseudorandom number generator state
199+
* @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true)
200+
* @throws must provide a valid state
201+
* @returns pseudorandom number generator
202+
*
203+
* @example
204+
* var rand = hypergeometric.factory();
205+
* var v = rand( 10, 5, 7 );
206+
* // returns <number>
207+
*
208+
* @example
209+
* var rand = hypergeometric.factory({
210+
* 'seed': 297
211+
* });
212+
* var v = rand( 5, 3, 2 );
213+
* // returns <number>
214+
*/
215+
factory( options?: Options ): BinaryFunction;
216+
}
217+
218+
/**
219+
* Returns pseudorandom number drawn from a hypergeometric distribution.
220+
*
221+
* ## Notes
222+
*
223+
* - `N`, `K`, and `n` must all be nonnegative integers; otherwise, the function returns `NaN`.
224+
* - If `n > N` or `K > N`, the function returns `NaN`.
225+
*
226+
* @param N - population size
227+
* @param K - subpopulation size
228+
* @param n - number of draws
229+
* @returns pseudorandom number
230+
*
231+
* @example
232+
* var v = hypergeometric( 10, 5, 7 );
233+
* // returns <number>
234+
*
235+
* @example
236+
* var rand = hypergeometric.factory({
237+
* 'seed': 297
238+
* });
239+
* var v = rand( 5, 3, 2 );
240+
* // returns <number>
241+
*/
242+
declare var hypergeometric: Random;
243+
244+
245+
// EXPORTS //
246+
247+
export = hypergeometric;

0 commit comments

Comments
 (0)