1/*
2  Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization
3  dedicated to making software imaging solutions freely available.
4
5  You may not use this file except in compliance with the License.
6  obtain a copy of the License at
7
8    http://www.imagemagick.org/script/license.php
9
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15
16  MagickCore random generation private methods.
17*/
18#ifndef MAGICKCORE_RANDOM_PRIVATE_H
19#define MAGICKCORE_RANDOM_PRIVATE_H
20
21#include "MagickCore/thread-private.h"
22
23#if defined(__cplusplus) || defined(c_plusplus)
24extern "C" {
25#endif
26
27extern MagickPrivate double
28  GetRandomInfoNormalize(const RandomInfo *);
29
30extern MagickPrivate MagickBooleanType
31  RandomComponentGenesis(void);
32
33extern MagickPrivate unsigned long
34  *GetRandomInfoSeed(RandomInfo *);
35
36extern MagickPrivate void
37  RandomComponentTerminus(void);
38
39static inline RandomInfo **DestroyRandomInfoThreadSet(
40  RandomInfo **random_info)
41{
42  register ssize_t
43    i;
44
45  assert(random_info != (RandomInfo **) NULL);
46  for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++)
47    if (random_info[i] != (RandomInfo *) NULL)
48      random_info[i]=DestroyRandomInfo(random_info[i]);
49  return((RandomInfo **) RelinquishMagickMemory(random_info));
50}
51
52static inline RandomInfo **AcquireRandomInfoThreadSet(void)
53{
54  register ssize_t
55    i;
56
57  RandomInfo
58    **random_info;
59
60  size_t
61    number_threads;
62
63  number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
64  random_info=(RandomInfo **) AcquireQuantumMemory(number_threads,
65    sizeof(*random_info));
66  if (random_info == (RandomInfo **) NULL)
67    return((RandomInfo **) NULL);
68  (void) ResetMagickMemory(random_info,0,number_threads*sizeof(*random_info));
69  for (i=0; i < (ssize_t) number_threads; i++)
70  {
71    random_info[i]=AcquireRandomInfo();
72    if (random_info[i] == (RandomInfo *) NULL)
73      return(DestroyRandomInfoThreadSet(random_info));
74  }
75  return(random_info);
76}
77
78#if defined(__cplusplus) || defined(c_plusplus)
79}
80#endif
81
82#endif
83