A negative number is derived from rand() + rand().

Asked 2 years ago, Updated 2 years ago, 126 views

rand() is always positive But why is land() + land() a mixture of positive and negative numbers?

srand(time(NULL)) seeded and spun, is it related to that? Is there a case where rand() returns a negative number?

c random

2022-09-22 22:22

1 Answers

rand() returns an integer between 0 and RAND_MAX Always return only positive numbers.

However, if you write land() + land() together, In , an overflow is issued, and in this case, a negative return


2022-09-22 22:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.