objc2_gameplay_kit/generated/
GKRandomDistribution.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9extern_class!(
10    /// A random distribution is a random source itself with a specific mapping from the input source to the output values.
11    /// The distribution is uniform, meaning there is no bias towards any of the possible outcomes.
12    ///
13    /// See also [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkrandomdistribution?language=objc)
14    #[unsafe(super(NSObject))]
15    #[derive(Debug, PartialEq, Eq, Hash)]
16    pub struct GKRandomDistribution;
17);
18
19#[cfg(feature = "GKRandomSource")]
20extern_conformance!(
21    unsafe impl GKRandom for GKRandomDistribution {}
22);
23
24extern_conformance!(
25    unsafe impl NSObjectProtocol for GKRandomDistribution {}
26);
27
28impl GKRandomDistribution {
29    extern_methods!(
30        /// The lowest value the distribution will output.
31        #[unsafe(method(lowestValue))]
32        #[unsafe(method_family = none)]
33        pub unsafe fn lowestValue(&self) -> NSInteger;
34
35        /// The highest value the distribution will output.
36        #[unsafe(method(highestValue))]
37        #[unsafe(method_family = none)]
38        pub unsafe fn highestValue(&self) -> NSInteger;
39
40        /// The number of unique possible outcomes, depending on the distribution type this is not always highest - lowest + 1.
41        #[unsafe(method(numberOfPossibleOutcomes))]
42        #[unsafe(method_family = none)]
43        pub unsafe fn numberOfPossibleOutcomes(&self) -> NSUInteger;
44
45        #[cfg(feature = "GKRandomSource")]
46        /// Initializes a random distribution within the range [lowest, highest] using a source to grab input values from.
47        #[unsafe(method(initWithRandomSource:lowestValue:highestValue:))]
48        #[unsafe(method_family = init)]
49        pub unsafe fn initWithRandomSource_lowestValue_highestValue(
50            this: Allocated<Self>,
51            source: &ProtocolObject<dyn GKRandom>,
52            lowest_inclusive: NSInteger,
53            highest_inclusive: NSInteger,
54        ) -> Retained<Self>;
55
56        /// Returns the next integer in the distribution sequence and moves ahead to the next one.
57        /// The value is in the range of [lowest, highest].
58        #[unsafe(method(nextInt))]
59        #[unsafe(method_family = none)]
60        pub unsafe fn nextInt(&self) -> NSInteger;
61
62        /// Returns the next unsigned value in the distribution sequence that is less than upperBound.
63        /// The value never equals or exceeeds upperBounds, and in this case it will also never exceed
64        /// the highest value of the distribution.
65        #[unsafe(method(nextIntWithUpperBound:))]
66        #[unsafe(method_family = none)]
67        pub unsafe fn nextIntWithUpperBound(&self, upper_bound: NSUInteger) -> NSUInteger;
68
69        /// Returns the next uniform float in the random sequence and moves ahead to the next one.
70        /// The value is in the range of [lowest / higest, 1.0].
71        ///
72        /// The value is quantized to the distribution's lowest and highest bounds. Thus on a d20
73        /// distribution the value is quantized to 5% increments. The output value 0 is not possible
74        /// to get unless the lowest value bound is also 0 or below.
75        ///
76        ///
77        /// See: nextInt
78        #[unsafe(method(nextUniform))]
79        #[unsafe(method_family = none)]
80        pub unsafe fn nextUniform(&self) -> c_float;
81
82        /// Returns the next true or false value in the distribution sequence and moves ahead to the next one.
83        /// The value is either nonzero (true) or zero (false).
84        /// Use this for simple boolean switches in logic that don't require fuzzy evaluation.
85        /// For fuzzy evaluation use nextUniform.
86        ///
87        /// By default this is based on the referenced source's definition of nextBool.
88        ///
89        ///
90        /// See: GKRandomSource.nextBool
91        #[unsafe(method(nextBool))]
92        #[unsafe(method_family = none)]
93        pub unsafe fn nextBool(&self) -> bool;
94
95        /// Convenience creation of random distribution within the range [lowest, highest] using an isolated source to grab input values from.
96        /// This is equivalent to calling alloc followed by initWithSource:lowest:highest:, where source is [[GKRandomSource alloc] init].
97        ///
98        /// See: initWithRandomSource:lowestValue:highestValue:
99        #[unsafe(method(distributionWithLowestValue:highestValue:))]
100        #[unsafe(method_family = none)]
101        pub unsafe fn distributionWithLowestValue_highestValue(
102            lowest_inclusive: NSInteger,
103            highest_inclusive: NSInteger,
104        ) -> Retained<Self>;
105
106        /// Convenience creation of random distribution with the die like range [1, sideCount] using an isolated source to grab input values from.
107        /// This is equivalent to calling alloc followed by initWithSource:lowest:highest:, where source is [[GKRandomSource alloc] init].
108        ///
109        /// See: initWithRandomSource:lowestValue:highestValue:
110        #[unsafe(method(distributionForDieWithSideCount:))]
111        #[unsafe(method_family = none)]
112        pub unsafe fn distributionForDieWithSideCount(side_count: NSInteger) -> Retained<Self>;
113
114        /// Convenience creation for the very common d6 range [1, 6] with an isolated random source
115        /// shielded from outside sources.
116        #[unsafe(method(d6))]
117        #[unsafe(method_family = none)]
118        pub unsafe fn d6() -> Retained<Self>;
119
120        /// Convenience creation for the very common d20 range [1, 20] with an isolated random source
121        /// shielded from outside sources.
122        #[unsafe(method(d20))]
123        #[unsafe(method_family = none)]
124        pub unsafe fn d20() -> Retained<Self>;
125    );
126}
127
128/// Methods declared on superclass `NSObject`.
129impl GKRandomDistribution {
130    extern_methods!(
131        #[unsafe(method(init))]
132        #[unsafe(method_family = init)]
133        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
134
135        #[unsafe(method(new))]
136        #[unsafe(method_family = new)]
137        pub unsafe fn new() -> Retained<Self>;
138    );
139}
140
141extern_class!(
142    /// A gaussian distribution is biased towards the mean value, the possible outcomes are spread out from the mean
143    /// with decreasing probability. Values within 1 deviation of the mean make up 68.27% of the distribution, values
144    /// within 2 deviations make up 95% and values within 3 deviations make up 99.7%.
145    ///
146    /// Note that a gaussian distribution's unbounded behavior beyond 3 deviations is undesired,
147    /// thus this distribution deviates nominally by modifying the bounds to 3 deviations.
148    /// Thus values within 3 deviations actually make up 100% of the distribution.
149    ///
150    /// See also [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkgaussiandistribution?language=objc)
151    #[unsafe(super(GKRandomDistribution, NSObject))]
152    #[derive(Debug, PartialEq, Eq, Hash)]
153    pub struct GKGaussianDistribution;
154);
155
156#[cfg(feature = "GKRandomSource")]
157extern_conformance!(
158    unsafe impl GKRandom for GKGaussianDistribution {}
159);
160
161extern_conformance!(
162    unsafe impl NSObjectProtocol for GKGaussianDistribution {}
163);
164
165impl GKGaussianDistribution {
166    extern_methods!(
167        /// The mean, or expected, value of the distribution. Values are more probable the closer to the mean they are.
168        #[unsafe(method(mean))]
169        #[unsafe(method_family = none)]
170        pub unsafe fn mean(&self) -> c_float;
171
172        /// The deviation, often called 'sigma', is the deviation from the mean that would include roughly 68% of the distribution.
173        /// The range of the distribution is [mean - 3 * deviation, mean + 3 * deviation]. Values beyond 3 deviations
174        /// are considered so improbable that they are removed from the output set.
175        #[unsafe(method(deviation))]
176        #[unsafe(method_family = none)]
177        pub unsafe fn deviation(&self) -> c_float;
178
179        #[cfg(feature = "GKRandomSource")]
180        /// Initializes a Gaussian random distribution within the range [lowest, highest] using a source to grab input values from.
181        /// This sets the gaussian parameters to:
182        ///
183        /// mean = (highest + lowest) / 2
184        /// deviation = (highest - lowest) / 6
185        ///
186        /// The mean and deviation will be floating point numbers even if the distribution is meant to produce integer values.
187        ///
188        /// See: mean
189        ///
190        /// See: deviation
191        #[unsafe(method(initWithRandomSource:lowestValue:highestValue:))]
192        #[unsafe(method_family = init)]
193        pub unsafe fn initWithRandomSource_lowestValue_highestValue(
194            this: Allocated<Self>,
195            source: &ProtocolObject<dyn GKRandom>,
196            lowest_inclusive: NSInteger,
197            highest_inclusive: NSInteger,
198        ) -> Retained<Self>;
199
200        #[cfg(feature = "GKRandomSource")]
201        /// Initializes a Gaussian random distribution within the range [mean - 3 * deviation, mean + 3 * deviation]
202        /// using a source to grab input values from.
203        #[unsafe(method(initWithRandomSource:mean:deviation:))]
204        #[unsafe(method_family = init)]
205        pub unsafe fn initWithRandomSource_mean_deviation(
206            this: Allocated<Self>,
207            source: &ProtocolObject<dyn GKRandom>,
208            mean: c_float,
209            deviation: c_float,
210        ) -> Retained<Self>;
211    );
212}
213
214/// Methods declared on superclass `GKRandomDistribution`.
215impl GKGaussianDistribution {
216    extern_methods!(
217        /// Convenience creation of random distribution within the range [lowest, highest] using an isolated source to grab input values from.
218        /// This is equivalent to calling alloc followed by initWithSource:lowest:highest:, where source is [[GKRandomSource alloc] init].
219        ///
220        /// See: initWithRandomSource:lowestValue:highestValue:
221        #[unsafe(method(distributionWithLowestValue:highestValue:))]
222        #[unsafe(method_family = none)]
223        pub unsafe fn distributionWithLowestValue_highestValue(
224            lowest_inclusive: NSInteger,
225            highest_inclusive: NSInteger,
226        ) -> Retained<Self>;
227
228        /// Convenience creation of random distribution with the die like range [1, sideCount] using an isolated source to grab input values from.
229        /// This is equivalent to calling alloc followed by initWithSource:lowest:highest:, where source is [[GKRandomSource alloc] init].
230        ///
231        /// See: initWithRandomSource:lowestValue:highestValue:
232        #[unsafe(method(distributionForDieWithSideCount:))]
233        #[unsafe(method_family = none)]
234        pub unsafe fn distributionForDieWithSideCount(side_count: NSInteger) -> Retained<Self>;
235
236        /// Convenience creation for the very common d6 range [1, 6] with an isolated random source
237        /// shielded from outside sources.
238        #[unsafe(method(d6))]
239        #[unsafe(method_family = none)]
240        pub unsafe fn d6() -> Retained<Self>;
241
242        /// Convenience creation for the very common d20 range [1, 20] with an isolated random source
243        /// shielded from outside sources.
244        #[unsafe(method(d20))]
245        #[unsafe(method_family = none)]
246        pub unsafe fn d20() -> Retained<Self>;
247    );
248}
249
250/// Methods declared on superclass `NSObject`.
251impl GKGaussianDistribution {
252    extern_methods!(
253        #[unsafe(method(init))]
254        #[unsafe(method_family = init)]
255        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
256
257        #[unsafe(method(new))]
258        #[unsafe(method_family = new)]
259        pub unsafe fn new() -> Retained<Self>;
260    );
261}
262
263extern_class!(
264    /// A shuffled distribution tries to make sure individual samples are not clustered whilst retaining a uniform distribution of values
265    /// over time. This is often referred to as fair or less random, as the predicatability of the outcomes in a series is vastly increased,
266    /// yet the distribution of values is uniform.
267    ///
268    /// Do not use with distributions ranging more than 256 between lowest and highest as the shuffling seqeunce is stored internally in memory.
269    ///
270    /// See also [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkshuffleddistribution?language=objc)
271    #[unsafe(super(GKRandomDistribution, NSObject))]
272    #[derive(Debug, PartialEq, Eq, Hash)]
273    pub struct GKShuffledDistribution;
274);
275
276#[cfg(feature = "GKRandomSource")]
277extern_conformance!(
278    unsafe impl GKRandom for GKShuffledDistribution {}
279);
280
281extern_conformance!(
282    unsafe impl NSObjectProtocol for GKShuffledDistribution {}
283);
284
285impl GKShuffledDistribution {
286    extern_methods!();
287}
288
289/// Methods declared on superclass `GKRandomDistribution`.
290impl GKShuffledDistribution {
291    extern_methods!(
292        #[cfg(feature = "GKRandomSource")]
293        /// Initializes a random distribution within the range [lowest, highest] using a source to grab input values from.
294        #[unsafe(method(initWithRandomSource:lowestValue:highestValue:))]
295        #[unsafe(method_family = init)]
296        pub unsafe fn initWithRandomSource_lowestValue_highestValue(
297            this: Allocated<Self>,
298            source: &ProtocolObject<dyn GKRandom>,
299            lowest_inclusive: NSInteger,
300            highest_inclusive: NSInteger,
301        ) -> Retained<Self>;
302
303        /// Convenience creation of random distribution within the range [lowest, highest] using an isolated source to grab input values from.
304        /// This is equivalent to calling alloc followed by initWithSource:lowest:highest:, where source is [[GKRandomSource alloc] init].
305        ///
306        /// See: initWithRandomSource:lowestValue:highestValue:
307        #[unsafe(method(distributionWithLowestValue:highestValue:))]
308        #[unsafe(method_family = none)]
309        pub unsafe fn distributionWithLowestValue_highestValue(
310            lowest_inclusive: NSInteger,
311            highest_inclusive: NSInteger,
312        ) -> Retained<Self>;
313
314        /// Convenience creation of random distribution with the die like range [1, sideCount] using an isolated source to grab input values from.
315        /// This is equivalent to calling alloc followed by initWithSource:lowest:highest:, where source is [[GKRandomSource alloc] init].
316        ///
317        /// See: initWithRandomSource:lowestValue:highestValue:
318        #[unsafe(method(distributionForDieWithSideCount:))]
319        #[unsafe(method_family = none)]
320        pub unsafe fn distributionForDieWithSideCount(side_count: NSInteger) -> Retained<Self>;
321
322        /// Convenience creation for the very common d6 range [1, 6] with an isolated random source
323        /// shielded from outside sources.
324        #[unsafe(method(d6))]
325        #[unsafe(method_family = none)]
326        pub unsafe fn d6() -> Retained<Self>;
327
328        /// Convenience creation for the very common d20 range [1, 20] with an isolated random source
329        /// shielded from outside sources.
330        #[unsafe(method(d20))]
331        #[unsafe(method_family = none)]
332        pub unsafe fn d20() -> Retained<Self>;
333    );
334}
335
336/// Methods declared on superclass `NSObject`.
337impl GKShuffledDistribution {
338    extern_methods!(
339        #[unsafe(method(init))]
340        #[unsafe(method_family = init)]
341        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
342
343        #[unsafe(method(new))]
344        #[unsafe(method_family = new)]
345        pub unsafe fn new() -> Retained<Self>;
346    );
347}