]> www.ginac.de Git - cln.git/blob - src/integer/random/cl_I_random.cc
* All Files have been modified for inclusion of namespace cln;
[cln.git] / src / integer / random / cl_I_random.cc
1 // random_I().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cln/integer.h"
8
9
10 // Implementation.
11
12 #include "cl_random_impl.h"
13 #include "cl_I.h"
14 #include "cl_DS.h"
15
16 namespace cln {
17
18 const cl_I random_I (random_state& randomstate, const cl_I& n)
19 {
20         CL_ALLOCA_STACK;
21         var const uintD* n_MSDptr;
22         var uintC n_len;
23         var const uintD* n_LSDptr;
24         I_to_NDS_nocopy(n, n_MSDptr=,n_len=,n_LSDptr=,cl_false,); // Digit sequence >0 zu n
25         var uintD* MSDptr;
26         var uintC len = n_len + ceiling(16,intDsize); // 16 Bits mehr
27         // neue UDS mit len Zufallsdigits bilden:
28         num_stack_alloc(len,MSDptr=,);
29         random_UDS(randomstate,MSDptr,len);
30         // und durch n dividieren:
31         var DS q;
32         var DS r;
33         UDS_divide(MSDptr,len,MSDptr mspop len, n_MSDptr,n_len,n_LSDptr, &q,&r);
34         // Rest in Integer umwandeln:
35         return NUDS_to_I(r.MSDptr,r.len);
36 }
37
38 }  // namespace cln