pseudo-random number generator problem

Hi guys im trying to make my own pseudo-random number generator from the algorithm below using the kent chaotic map.

1
2
3
4
5
       
             { x(n)/m,  0 < x(n) <=m
x(n+1)= {
             {(1-x(n))/1-m,  m<x(n) <1


where 0<m<1 (m could be 0.7 for example and all other variables could be anything) I've tried playing around with loops for example but cant get it working:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

int main (int argc, char * const argv[])
{
   	double m = 0.7;
	double x[10];
	double k = 10;
	int n, Chaotic_map;
{	
	for (n=0;n<k;n++)
		x[n]+1=x[n]/m;
	
	for (m<x[n]<1)
		Chaotic_map= x[n]+1=(1-x[n])/(1-m);
	printf("%d", Chaotic_map);
	 
    return 0;
}


But im still lost, Any ideas??


It's quite a mess you wrote there..
line 9, why is there a {.
line 13, this is neither how you check if a number is in range, nor something you should put in the for loop.
lines 11, 14, you can't assign to a sum. It is only a temporary value. You wanted x[n+1].
Though that would still not work.
The algorithm is
1
2
if(x[n] is between 0 and m) x[n+1] = x[n]/m;
else if(x[n] is between m and 1) x[n+1] = (1-x[n])/(1-m);

Normally you would check whether a number x is in some range (a; b) with x > a && x < b, but in this case, if x[n] is not in range (0; 1), the algorithm won't work. In a way, this ensures that x[n] will be in that range, so the ifs become
1
2
if( x[n] <= m ) x[n+1] = ...
else x[n+1] = ...

So what you want to do is do a for( n = 1; n < k; n++ ) and put there the if I wrote. Note that n starts from 1. That is because x[1] depends on x[0]. That is, x[0] has to be given as an input.
it works now, thanks alot!
Topic archived. No new replies allowed.