Suggestion for testlib's random functions

Правка en11, от DeadlyCritic, 2020-06-15 11:14:44

In the name of God;

Hi, here I want to suggest some random functions for Testlib.

Testlib has nice random functions, here I want to suggest some other ones. The first and the second random functions are available in testlib, but the rest are not.

1, $$$\text{rnd.next(l, r)}$$$, it will return a random number in range $$$l$$$ to $$$r$$$ with equal weights :

2, $$$\text{rnd.wnext(l, r, w)}$$$, it will return a random number in range $$$l$$$ to $$$r$$$ with monotonically increasing/decreasing weights depending on $$$w$$$ :

If $$$w = 0$$$ then it will be equal to $$$\text{rnd.next(l, r)}$$$.

If $$$w > 0$$$ :

If $$$w < 0$$$ :

3, $$$\text{rnd.cnext(l, r, c)}$$$, it will return a random number in range $$$l$$$ to $$$r$$$ :

If $$$c = 0$$$ then it will be equal to $$$\text{rnd.next(l, r)}$$$

If $$$c > 0$$$ :

If $$$c < 0$$$, (I couldn't find a accurate graph for it) :

4, $$$\text{rnd.cnext(l, r, c1, c2)}$$$, it will return a random number in range $$$l$$$ to $$$r$$$ like $$$\text{rnd.cnext(l, r, c)}$$$, but its not centered around $$$\frac {r+l} 2$$$ : ($$$c1 \ge 0$$$ and $$$c2 \ge 0$$$)

About the implementation of $$$\text{cnext(l, r, c1, c2)}$$$, its as follow :

  1. Choose $$$c1+c2+1$$$ random numbers in rage $$$l$$$ to $$$r$$$ and sort them.

  2. Return $$$c1+1$$$-th one.

As you can see if $$$c1 = c2$$$ then its equal to $$$\text{cnext(l, r, c1)}$$$.

If $$$c1 = 0$$$ then it will be equal to $$$\text{wnext(l, r, -c2)}$$$, if $$$c2 = 0$$$ then it will be equal to $$$\text{wnext(l, r, c1)}$$$.

You want to say that they are useless? Indeed they are very useful, open your eyes and find some examples! Please share them in the comment section.

Теги random, testlib

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en13 Английский DeadlyCritic 2020-06-15 16:32:35 205
en12 Английский DeadlyCritic 2020-06-15 11:35:10 11
en11 Английский DeadlyCritic 2020-06-15 11:14:44 7 Tiny change: 'em.\n\n2. Print $c1+1$-th' -> 'em.\n\n2. Return $c1+1$-th'
en10 Английский DeadlyCritic 2020-06-15 11:10:15 166
en9 Английский DeadlyCritic 2020-06-15 11:04:43 476 (published)
en8 Английский DeadlyCritic 2020-06-15 10:47:50 83
en7 Английский DeadlyCritic 2020-06-15 10:46:37 188
en6 Английский DeadlyCritic 2020-06-15 10:38:02 331
en5 Английский DeadlyCritic 2020-06-15 10:07:41 82
en4 Английский DeadlyCritic 2020-06-15 10:07:00 183
en3 Английский DeadlyCritic 2020-06-15 10:04:43 96
en2 Английский DeadlyCritic 2020-06-15 09:57:51 23 Tiny change: 'es :\n\n![looool](/predown' -> 'es :\n\n![ ](/predown'
en1 Английский DeadlyCritic 2020-06-15 09:56:56 676 Initial revision (saved to drafts)