# Generate random polynomial with bounded coefficients

**URL:** <https://openfhe.discourse.group/t/generate-random-polynomial-with-bounded-coefficients/278>\
**Category:** Library Questions\
**Created:** [December 8, 2022, 3:25pm UTC](https://openfhe.discourse.group/t/generate-random-polynomial-with-bounded-coefficients/278 "2022-12-08T15:25:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![FMazzone](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/fmazzone/32/78_2.png) [@FMazzone](https://openfhe.discourse.group/u/FMazzone)\
**Post date:** [December 8, 2022, 3:25pm UTC](https://openfhe.discourse.group/t/generate-random-polynomial-with-bounded-coefficients/278/1 "2022-12-08T15:25:23Z")

</div>

Context: CKKS.  
If I want to generate a uniformly random DCRTPoly I can just do something like:

```auto
DCRTPoly::DugType dug;
DCRTPoly randPoly(dug, elementParams, Format::EVALUATION);

```

where `elementParams` are parameters from an instance of CKKS. This way `randPoly` seems to be living in the latest level Q\_L.

If I want a random polynomial at a lower level, I can just drop some elements in the CRT form with `DropLastElement()`.

But what if I want a random polynomial living in R\_{Q\_l} whose norm is strictly lower than Q\_l? (let’s say bounded by B with Q\_{l -1} \< B \< Q\_l)  
Should I first create a normal `Poly` mod B and then turn it into CRT representation?  
(note that then I need to perform operations between this polynomial and other `DCRTPoly`s in R\_{Q\_l})

If anyone had a code snippet for this, it would be really appreciated.

---

<div class="post-metadata">

**Author:** ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)\
**Post date:** [December 8, 2022, 6:57pm UTC](https://openfhe.discourse.group/t/generate-random-polynomial-with-bounded-coefficients/278/2 "2022-12-08T18:57:47Z")

</div>

I think this [constructor](https://github.com/openfheorg/openfhe-development/blob/main/src/core/include/lattice/hal/default/dcrtpoly.h#L192) might be of help.
