srand Questions

2

Solved

Is it allowed for srand(0) to have the same effect as srand(1)? C11, 7.22.2.2 The srand function (empahasis added): The srand function uses the argument as a seed for a new sequence of pseudo-rand...
Affinitive asked 25/10, 2022 at 11:15

3

Whenever I try to use srand function I get this warning "implicit declaration of function 'time' [-Wimplicit-function-declaration]|" and a windows error report appears when running the compile...
Rational asked 17/3, 2013 at 7:6

5

Solved

I am currently running a multithreading simulation application with 8+ pipes (threads). These pipes run a very complex code that depends on a random sequence generated by a seed. The sequence is th...
Cleodal asked 1/11, 2013 at 19:53

4

I am asking to see if there is a way of increasing the speed the srand(time(NULL)); function "refreshes"? I understand srand() produces a new seed according to time (so once a second), but I am loo...
Binnie asked 11/6, 2015 at 7:7

5

This comment, which states: srand(time(0)); I would put this line as the first line in main() instead if calling it multiple times (which will actually lead to less random numbers). ...and I...
Corymb asked 30/11, 2014 at 2:10

4

Solved

About 3 years ago I coded a 2D random walk togheter with a coleague in C++, first it seemed to work properly as we obtained a diferent pattern each time. But whenever we decided to increase the num...
Edom asked 27/5, 2020 at 9:39

15

Solved

I need a 'good' way to initialize the pseudo-random number generator in C++. I've found an article that states: In order to generate random-like numbers, srand is usually initialized to some d...
Amadoamador asked 27/11, 2008 at 4:37

1

Solved

Since I found this particular documentation on https://www.tutorialspoint.com/c_standard_library/c_function_rand.htm,I have been thinking about this particular line of code srand((unsigned)time(&am...
Quinquereme asked 17/4, 2019 at 15:47

5

Solved

I need to start the same random number list over every execution of my app. srand/rand do not exist anymore. What should I do then? private extension Array { private func randomValues(_ seed: UIn...
Caviar asked 17/6, 2016 at 3:42

7

Solved

So, I'm trying to create a random vector (think geometry, not an expandable array), and every time I call my random vector function I get the same x value, though y and z are different. int main (...
Salami asked 13/6, 2010 at 15:18

2

Solved

Trying to solve an exercise where I have to print a random temperature value between 35°C & -10°C every 5 seconds followed by the date and time. Everything looks to be working as intended, howe...
Blackcap asked 24/2, 2016 at 21:16

8

Solved

I've got a vector that I'm trying to fill up with random numbers. I keep running into an issue however that the vector mostly outputs 0 each time that I'm running it (it shouldn't output a 0 ever)....
Ecthyma asked 2/2, 2014 at 21:38

7

Solved

This question is about a comment in this question Recommended way to initialize srand? The first comment says that srand() should be called only ONCE in an application. Why is it so?
Wadleigh asked 8/9, 2011 at 6:13

4

Solved

I understand that rand() function generates the same number(s) each you run it if you don't change the seed number. That's where srand() comes in. Time is always changing so I know that you should ...
Dann asked 22/1, 2014 at 3:21

3

I am working on a C++ assignment for my class, and we have to use rand () with a seed of 99 to produce a set of values. However, my problem is that when I try to create a value within our parameter...
Point asked 11/2, 2017 at 0:35

7

Solved

I just found out the hard way that srand(1) resets the PRNG of C(++) to the state before any call to srand (as defined in the reference). However, the seed 0 seems to do the same, or the state befo...
Unexampled asked 8/11, 2011 at 11:16

5

Solved

I have several threads running concurrently and each of them must generate random numbers. I want to understand if there is a pattern to follow, to understand if it is correct to initialize the ran...
Aplomb asked 17/10, 2011 at 18:0

7

Solved

According to my understanding, setting srand with a particular seed causes the sequence of calls to rand() to produce the same series of numbers each time for that particular seed: Eg: srand(se...
Medick asked 22/2, 2014 at 2:58

2

I have a optimisation algorithm which uses rand() and srand(). In order to be able to test the behaviour I have set the seed to a specific number in order to get the same sequence of random numbers...
Romonaromonda asked 6/2, 2015 at 21:6

1

Solved

I have a Deck vector with 52 Card, and I want to shuffle it. vector<Card^> cards; So I used this: random_shuffle(cards.begin(), cards.end()); The problem was that it gave me the same re...
Footway asked 12/10, 2014 at 0:23

4

Solved

Background: I use rand(), std::rand(), std::random_shuffle() and other functions in my code for scientific calculations. To be able to reproduce my results, I always explicitly specify the random s...
Soler asked 10/10, 2014 at 7:33

1

In rand() considered harmful it is pointed out that srand(time(NULL)) is bad because srand takes an unsigned int, but for Microsoft's compiler, time_t by default is a 64-bit number, therefore a nar...
Banker asked 5/10, 2014 at 20:15

2

Solved

When you call srand() inside of a function, does it only seed rand() inside of that function? Here is the function main where srand() is called. int main(){ srand(static_cast<unsigned int>...
Propolis asked 25/9, 2014 at 19:15

5

Solved

My program contains code that should generate a random positive integer number every time I execute it. It generates random numbers but only once. After that, when I execute same code, it giv...
Centurial asked 15/5, 2013 at 15:31

3

Solved

I've seen some guide on generating random numbers with C: two things got me wondering: it is said that in addition to stdlib.h and time.h libraries I have to include the math.h library for it to...
Icaria asked 16/4, 2014 at 12:43

© 2022 - 2024 — McMap. All rights reserved.