srand Questions

1

Solved

In a function, I want to generate a list of numbers in range: (This function will be called only once when executing the program.) void DataSet::finalize(double trainPercent, bool genValidData) { ...
Adallard asked 19/3, 2014 at 5:22

3

Solved

I'm using the random_shuffle on a vector like this: #include <algorithm> vector <Card> deck; //some code to add cards to the deck here random_shuffle ( deck.begin(), deck.end() ); Wh...
Cage asked 19/11, 2012 at 18:34

3

Solved

Whenever I run the following program the returned values are always 6 or 13. #include <iostream> #include <fstream> #include <ctime> #include <cstdlib> using namespace std;...
Pournaras asked 28/11, 2013 at 10:12

3

Solved

For code that uses std::random_shuffle, I need to set a random seed so that the pseudorandom sequences produced vary in each program run. The code example here makes a call to srand ( unsigned ( ...
Passkey asked 21/1, 2013 at 15:17

1

Solved

Why am I not able to compile my code to c++ 11 and use the srand48 function? I have a program where I play around with some matrices. The problem is that when I compile the code with the -std=c++0...
Ancestry asked 16/5, 2013 at 7:36

5

The way I learned was to initially seed the random number generator with srand(time(NULL)) and then use calls to rand() to generate random numbers. The problem with this approach is if I run ...
Framing asked 6/4, 2013 at 2:42

5

Solved

Here is the code: #include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { int r; int i; for (i = 0; i < 100; i++) { r = rand() % 100 + 1; printf("%d\n...
Steradian asked 10/1, 2013 at 5:36

3

Solved

I'm writing a program that will generate numerous random numbers in loops. I'm trying to make the numbers somewhat less predictable (not only for security, but to avoid collisions on multiple threa...
Dana asked 26/11, 2012 at 1:11

1

Solved

I can find plenty of documentation as to issues with use of time() prior to Perl version 5.004, but nothing following. For a homework assignment, we are asked to reverse-engineer a program's resul...
Filippa asked 19/9, 2012 at 14:39

2

Solved

Part of what I'm developing is a random company name generator. It draws from several arrays of name parts. I use the rand() function to draw the random name parts. However, the same "random" numbe...
Cheyennecheyne asked 25/8, 2012 at 5:21

3

Solved

I'm doing a host for an AI contest, and have a randomBot that choice random possible values. The bot has 2 exported functions: Init(_seed) and MakeMove() To play exactly same games host have a de...
Gaygaya asked 10/6, 2012 at 4:26

4

Solved

I have a question about the following code : #include <iostream> #include <ctime> int main(){ unsigned long int blob; srand(time(0)); for(int counter = 0; counter <= 100; cou...
Doublefaced asked 9/4, 2012 at 14:40

4

Possible Duplicate: Generate Random numbers uniformly over entire range C++ random float How can I generate a random number between 5 and 25 in c++ ? #include <iostream> #incl...
Firewarden asked 18/11, 2011 at 16:34

4

Solved

I have a C++ application which calls rand() in various places. Do I need to initialize srand() regularly to ensure that rand() is reasonably random, or is it enough to call it once when the app sta...
Shalne asked 5/8, 2011 at 9:53

4

While working on some updates to my module List::Gen, I decided to add a ->pick(num) method, which will return a num sized list of random elements from its source. To test this, I used srand to ...
Susan asked 19/4, 2011 at 18:54

2

Solved

Is there a way to store the current state of the built in pseudo-random number generator in Perl so that when my program is run again, it can pick up the sequence from where it left off rather than...
Vetiver asked 2/3, 2010 at 0:18

10

Solved

for(i = 0; i < n; i++){ srand(time(NULL)); printf("%d ", time(NULL)); for(j = 0; j < (n-1); j++){ a[i][j] = rand(); } } I try to generate random numbers, but they are the same... I tr...
Jallier asked 15/3, 2010 at 18:21

5

Solved

Is it possible to print a random number in C++ from a set of numbers with ONE SINGLE statement? Let's say the set is {2, 5, 22, 55, 332} I looked up rand() but I doubt it's possible to do in a si...
Dioptrics asked 14/3, 2010 at 18:54

4

Solved

I've got an unmanaged c++ console application in which I'm using srand() and rand(). I don't need this to solve a particular problem, but was curious: is the original seed passed to srand() stored ...
Daughterly asked 27/8, 2009 at 19:30

4

Solved

I've seen quite a few recommendations for not seeding pseudo-random number generators more than once per execution, but never accompanied by a thorough explanation. Of course, it is easy to see why...
Complex asked 10/6, 2009 at 17:20

© 2022 - 2024 — McMap. All rights reserved.