How to generate a pseudo-random number between A and B (A, B - int) in GNU C with only the standard library
Thank!
Assuming A <B then how about this ...
srand((unsigned)time(NULL)); r = (rand()%(B-A)) + A;
According to the comments below, it is possible that BA is essentially larger than RAND_MAX. In this case, you need to be more careful.
srand , rand. rand 0 RAND_MAX; . - , , . , 7 , rand() % 7, (0, 1, 2, 3, 4, 5, 6) - 7. ( 7.) , .
srand
rand
RAND_MAX
rand() % 7
, srand , - main().
. .
Source: https://habr.com/ru/post/1779095/More articles:Java cannot find local files after calling PrinterJob.getPrinterJob (). DefaultPage () - javaHow to deploy a site for production with minimal impact on users - asp.netГендерная валидация в моделях с несколькими рельсами - ruby-on-railsError using sessionStorage - javascriptwpf; How to link the current date? - wpfFind Bezier curve height in canvas - canvashttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1779097/in-matlab-how-can-i-conveniently-supply-many-arguments-to-a-function&usg=ALkJrhhgbO8p6XNO69rj-GgMWQgkCDQHWACython, C and Fortran - cMVC, C # Passing parent.id to a child index or Create an action? - c #How to pass parent id to child view - vb.netAll Articles