Array and queue randomization: foreach and unique constraint

Let’s say that you need to generate a random queue of data.

The queue should have:

  • 10 elements
  • values between 1 and 100
  • each element is an even number
  • each element is unique 

 

You can use unique constraints in order to generate unique elements, and you can use foreach to go through all the elements in the queue.

Bonus tip:

If you also need to sort the array you can use post_randomize() and sort().

Another tip:

https://www.edaplayground.com/x/EfLK

You can add a condition when using foreach, like this:

After running the program, you get:

Contact Us

Please, enter your details below. We will get back to you as fast as we can.

This website uses cookies to ensure you get the best experience on our website.

Get Cogita

Please, enter your details below. We will get back to you as fast as we can.

Thank you!

We will get in touch soon.

Get a Quote

Please, enter your details below. We will get back to you as fast as we can.