how can i get periodicity of random function in c++ [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I want to calculate pattern at which stage random numbers repeat
string a="abcd";
for(int i=0;i<10000;i++)
{
a=swap(a[i%4],a[rand()]%4)
cout<<a<<"\n";
}
I want to calculate the stage at which, string pattern will same

Most random number generators' sequences do not repeat on successive calls to rand, and can pass tests for randomness.
The actual algorithm used in your C++ implementation can vary, and can be one of the algorithms listed here:
https://en.cppreference.com/w/cpp/numeric/random
Each has its own theory and implementation.
For example, the generation of one of the most common ones the Linear Congruential , is explained here:
https://en.wikipedia.org/wiki/Linear_congruential_generator
It is important to note that most C++ random number generators will generate the same sequence of numbers on different runs of the application, when seeded with the same seed.

Related

Suppose you have an array of N elements. You need to find for how many i, Ai + A(i+1) is a square number. Is this question trivial? If so how? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I just wanted to know if the above question is trivial or not. More importantly, how can you recognize if an algorithm is trivial?
It depends what do you mean by trivial. If you talk about complexity, it is O(n*M(N)) where M(N) is the complexity of the underlying multiplication algorithm with N maximum of the array's values and n is the length of the array.
If you talk about implementation, it is one loop with one check that the sum of the neighbors is a perfect square. If the elements fit into int, double etc. you have sqrt function in the standard library. If your elements are arbitrary length integers or float point numbers, you either need to use an appropriate library or implement the handling of these numbers on your own, which might be not trivial.
This understanding should help you to answer your last question

How std::random_device generate non-deterministic random numbers? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Why std::random_device generate non-deterministic random numbers? What is the seed in this generator? It's not a time, so what?
It is not specified. Implementation is supposed to provide suitable ways of doing this, and usually they would recourse to OS-provided tools.
For example, on Linux there are /dev/[u]random devices which will provide entropy from a system state.

C++ sort() function algorithm [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Some days ago I wanted to use C++ sort() function to sort an array of strings, but I had a problem!
What algorithm does it use to sort the array? Is it a deterministic one or may it use different algorithms based on the type of the array?
Also, is there a clear time complexity analysis about it?
Does this function use the same algorithm for sorting numbers array and strings array?
It might or it might not. That is not specified by the standard.
And if we use it to sort an array of strings which the total size of them is less than 100,000 characters, would it work in less than 1 second(in the worst case)?
It might or it might not. It depends on the machine you're running the program on. Even if it will work in less than 1 second in worst case on a particular machine, it would be difficult to prove. But you can get a decent estimation by measuring. A measurement only applies to the machine it was performed, of course.

Why C++ not have in starting double main() or like that and only int/void main()? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Also how would I write a program to work on a very large number. I want to find the largest prime factor of a number in the range of 600000000000
Because that int main () returns an exit code of the program. If returned 0 - everything is fine. You need to perform calculations in this function because it is the program entry point. If the number is too large advise to use the example of long arithmetic.
int main => return 0; which indicates if the program finished it's running as the programmer expected. Return 2^31 gives one enough numbers for indicating error codes.
For large numbers linked lists can be used.

Mersenne Twister random generator - two VS2010 running in parrallel [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is it farfetched to assume that when two instances of VS2010 are running in parallel, seeds for random generator (Mersenne Twister) are taken from the same sequence ?
This would mean that seed for random generator is different whether I run the two programs one after another, or in parallel in two instances of VS.
The various random number generators don't seed themselves, you have to provide a seed.
If you don't, you most likely get 0. The implementation of Mersenne Twister et al does not
share data between instances, so multiple concurrent processes will operate independently.