13ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
27ce65e7125a4e1df1a274ce373c537a9df9c16cdCristy  Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization
33ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  dedicated to making software imaging solutions freely available.
43ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
53ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  You may not use this file except in compliance with the License.
63ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  obtain a copy of the License at
73ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    http://www.imagemagick.org/script/license.php
93ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Unless required by applicable law or agreed to in writing, software
113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  distributed under the License is distributed on an "AS IS" BASIS,
123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  See the License for the specific language governing permissions and
143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  limitations under the License.
153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickCore random generation private methods.
173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1883bceaa5d7a1196e05c1ccba443f90f4b032fca6Cristy#ifndef MAGICKCORE_RANDOM_PRIVATE_H
1983bceaa5d7a1196e05c1ccba443f90f4b032fca6Cristy#define MAGICKCORE_RANDOM_PRIVATE_H
203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
216398ec777e91813b64767e25358b7062a7de56cbcristy#include "MagickCore/thread-private.h"
226398ec777e91813b64767e25358b7062a7de56cbcristy
233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus)
243ed852eea50f9d4cd633efb8c2b054b8e33c253cristyextern "C" {
253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
27e85d0f75864c9410b905ac836b58f48db47303cccristyextern MagickPrivate double
286062eadcd2c1fd3186a66c5cb744a83129c6bb72cristy  GetRandomInfoNormalize(const RandomInfo *);
29e85d0f75864c9410b905ac836b58f48db47303cccristy
305ff4eaf57b3cd47d0371f204f865cbba614674a0cristyextern MagickPrivate MagickBooleanType
315ff4eaf57b3cd47d0371f204f865cbba614674a0cristy  RandomComponentGenesis(void);
325ff4eaf57b3cd47d0371f204f865cbba614674a0cristy
33e85d0f75864c9410b905ac836b58f48db47303cccristyextern MagickPrivate unsigned long
34e85d0f75864c9410b905ac836b58f48db47303cccristy  *GetRandomInfoSeed(RandomInfo *);
35e85d0f75864c9410b905ac836b58f48db47303cccristy
365ff4eaf57b3cd47d0371f204f865cbba614674a0cristyextern MagickPrivate void
375ff4eaf57b3cd47d0371f204f865cbba614674a0cristy  RandomComponentTerminus(void);
385ff4eaf57b3cd47d0371f204f865cbba614674a0cristy
393ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic inline RandomInfo **DestroyRandomInfoThreadSet(
403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  RandomInfo **random_info)
413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
42bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register ssize_t
433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(random_info != (RandomInfo **) NULL);
4692923f1e6fbf86ce3d345bf8e907e9d0aab70808cristy  for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++)
473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (random_info[i] != (RandomInfo *) NULL)
483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      random_info[i]=DestroyRandomInfo(random_info[i]);
49a64b85d7873d5e540fe6e2941aa98ec7653a4e2dcristy  return((RandomInfo **) RelinquishMagickMemory(random_info));
503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
523ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic inline RandomInfo **AcquireRandomInfoThreadSet(void)
533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
54bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register ssize_t
553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  RandomInfo
583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    **random_info;
593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
60bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  size_t
613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_threads;
623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6392923f1e6fbf86ce3d345bf8e907e9d0aab70808cristy  number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
64a64b85d7873d5e540fe6e2941aa98ec7653a4e2dcristy  random_info=(RandomInfo **) AcquireQuantumMemory(number_threads,
653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    sizeof(*random_info));
663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (random_info == (RandomInfo **) NULL)
673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((RandomInfo **) NULL);
683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ResetMagickMemory(random_info,0,number_threads*sizeof(*random_info));
69bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  for (i=0; i < (ssize_t) number_threads; i++)
703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    random_info[i]=AcquireRandomInfo();
723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (random_info[i] == (RandomInfo *) NULL)
733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(DestroyRandomInfoThreadSet(random_info));
743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(random_info);
763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus)
793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
83