001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.rng.core; 018 019import java.util.Arrays; 020 021import org.apache.commons.rng.RandomProviderState; 022 023/** 024 * Wraps the internal state of a generator instance. 025 * Its purpose is to store all the data needed to recover the same 026 * state in order to restart a sequence where it left off. 027 * External code should not try to modify the data contained in instances 028 * of this class. 029 * 030 * @since 1.0 031 */ 032public class RandomProviderDefaultState implements RandomProviderState { 033 /** Internal state. */ 034 private final byte[] state; 035 036 /** 037 * Initializes an instance. 038 * The contents of the {@code state} argument is unspecified, and is 039 * guaranteed to be valid only if it was generated by implementations 040 * provided by this library. 041 * 042 * @param state Mapping of all the data which an implementation of 043 * {@link org.apache.commons.rng.UniformRandomProvider} needs in order 044 * to reset its internal state. 045 */ 046 public RandomProviderDefaultState(byte[] state) { 047 this.state = Arrays.copyOf(state, state.length); 048 } 049 050 /** 051 * @return the internal state. 052 */ 053 public byte[] getState() { 054 return Arrays.copyOf(state, state.length); 055 } 056}