Download code

Jump to: navigation, search

Back to R250/521_(Java)

Download for Windows: single file, zip

Download for UNIX: single file, zip, tar.gz, tar.bz2

R250_521.java

 1 /* The authors of this work have released all rights to it and placed it
 2 in the public domain under the Creative Commons CC0 1.0 waiver
 3 (http://creativecommons.org/publicdomain/zero/1.0/).
 4 
 5 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 Retrieved from: http://en.literateprograms.org/R250/521_(Java)?oldid=4768
14 */
15 
16 public final class R250_521 {
17     private int[] r250_buffer = new int[250];
18     private int[] r521_buffer = new int[521];
19 
20     private int r250_index;
21     private int r521_index;
22 
23 
24     public R250_521() {
25         java.util.Random r = new java.util.Random();
26         int i = 521;
27     	
28         while (i-- > 250) {
29             r521_buffer[i] = r.nextInt();
30         }
31         while (i-- > 31) {
32             r250_buffer[i] = r.nextInt();
33             r521_buffer[i] = r.nextInt();
34         }
35         
36         int mask1 = 1;
37 	int mask2 = 0xFFFFFFFF;
38 	while (i-- > 0) {
39 	    r250_buffer[i] = (r.nextInt() | mask1) & mask2;
40 	    r521_buffer[i] = (r.nextInt() | mask1) & mask2;
41 	    mask2 ^= mask1;
42 	    mask1 >>= 1;
43 	}
44 	r250_buffer[0] = mask1;
45 	r521_buffer[0] = mask2;
46         r250_index = 0;
47 	r521_index = 0;
48 
49     }
50 
51     public int random() {
52         int i1 = r250_index;
53 	int i2 = r521_index;
54 	    
55 	int j1 = i1 - (250-103);
56 	if (j1 < 0)
57 	    j1 = i1 + 103;
58 	int j2 = i2 - (521-168);
59 	if (j2 < 0)
60 	    j2 = i2 + 168;
61         int r = r250_buffer[j1] ^ r250_buffer[i1];
62 	r250_buffer[i1] = r;
63 	int s = r521_buffer[j2] ^ r521_buffer[i2];
64 	r521_buffer[i2] = s;
65         i1 = (i1 != 250-1) ? (i1 + 1) : 0;
66 	r250_index = i1;
67 	i2 = (i2 != 521-1) ? (i2 + 1) : 0;
68 	r521_index = i2;
69         return r ^ s;
70     }
71 }


hijacker
hijacker
hijacker
hijacker