@@ -130,67 +130,77 @@ public static TData Random()
130130 switch ( e )
131131 {
132132 case SByte v :
133- return JemUtil . ValToGenericStruct < SByte , TData > ( checked ( ( sbyte ) Rng . Next ( 0 , SByte . MaxValue ) ) ) ;
133+ return Const ( checked ( ( sbyte ) Rng . Next ( 0 , SByte . MaxValue ) ) ) ;
134134 case Byte v :
135- return JemUtil . ValToGenericStruct < Byte , TData > ( checked ( ( byte ) Rng . Next ( 0 , Byte . MaxValue ) ) ) ;
135+ return Const ( checked ( ( byte ) Rng . Next ( 0 , Byte . MaxValue ) ) ) ;
136136 case Int32 v :
137- return JemUtil . ValToGenericStruct < Int32 , TData > ( checked ( ( int ) Rng . Next ( 0 , Int32 . MaxValue ) ) ) ;
137+ return Const ( checked ( ( int ) Rng . Next ( 0 , Int32 . MaxValue ) ) ) ;
138138 case UInt32 v :
139- return JemUtil . ValToGenericStruct < UInt32 , TData > ( checked ( ( uint ) Rng . Next ( 0 , Int32 . MaxValue ) ) ) ;
139+ return Const ( checked ( ( uint ) Rng . Next ( 0 , Int32 . MaxValue ) ) ) ;
140140 case Int16 v :
141- return JemUtil . ValToGenericStruct < Int16 , TData > ( checked ( ( short ) Rng . Next ( 0 , Int16 . MaxValue ) ) ) ;
141+ return Const ( checked ( ( short ) Rng . Next ( 0 , Int16 . MaxValue ) ) ) ;
142142 case UInt16 v :
143- return JemUtil . ValToGenericStruct < UInt16 , TData > ( checked ( ( ushort ) Rng . Next ( 0 , UInt16 . MaxValue ) ) ) ;
143+ return Const ( checked ( ( ushort ) Rng . Next ( 0 , UInt16 . MaxValue ) ) ) ;
144144 case Int64 v :
145- return JemUtil . ValToGenericStruct < Int64 , TData > ( checked ( ( long ) Rng . NextDouble ( ) * Int64 . MaxValue ) ) ;
145+ return Const ( checked ( ( long ) Rng . NextDouble ( ) * Int64 . MaxValue ) ) ;
146146 case UInt64 v :
147- return JemUtil . ValToGenericStruct < UInt64 , TData > ( checked ( ( ulong ) Rng . NextDouble ( ) * UInt64 . MaxValue ) ) ;
147+ return Const ( checked ( ( ulong ) Rng . NextDouble ( ) * UInt64 . MaxValue ) ) ;
148+ case Single v :
149+ return Const ( checked ( ( Single ) Rng . NextDouble ( ) * Int64 . MaxValue ) ) ;
150+ case Double v :
151+ return Const ( checked ( ( double ) Rng . NextDouble ( ) * Int64 . MaxValue ) ) ;
152+
148153 default :
149154 throw new ArithmeticException ( ) ;
150155 }
151156 }
152157
153- public static Tuple < TData , TData > RandomMultiplyFactorAndValue ( )
158+ public static TData Random ( double max )
159+ {
160+ return Const ( checked ( ( double ) Rng . NextDouble ( ) * max ) ) ;
161+ }
162+
163+ public static ( TData , TData ) RandomMultiplyFactorAndValue ( )
154164 {
155165 TData e = default ;
156166 TData max ;
157- int factor = Rng . Next ( 1 , 4 ) ;
167+ int factor = Rng . Next ( 0 , 4 ) ;
158168 switch ( e )
159169 {
160170 case SByte v :
161- max = JemUtil . ValToGenericStruct < sbyte , TData > ( ( sbyte . MaxValue / ( sbyte ) 4 ) ) ;
171+ max = Random ( ( sbyte ) ( sbyte . MaxValue / 4 ) ) ;
162172 break ;
163173 case Byte v :
164- max = JemUtil . ValToGenericStruct < byte , TData > ( ( byte ) ( byte . MaxValue / ( byte ) 4 ) ) ;
165- break ;
166- case Int32 v :
167- max = JemUtil . ValToGenericStruct < int , TData > ( ( int ) ( int . MaxValue / 4 ) ) ;
168- break ;
169- case UInt32 v :
170- max = JemUtil . ValToGenericStruct < uint , TData > ( uint . MaxValue / 4u ) ;
174+ max = Random ( ( byte ) ( byte . MaxValue / ( byte ) 4 ) ) ;
171175 break ;
172176 case Int16 v :
173- max = JemUtil . ValToGenericStruct < short , TData > ( ( short ) ( short . MaxValue / ( short ) 4 ) ) ;
177+ max = Random ( ( short ) ( short . MaxValue / ( short ) 4 ) ) ;
174178 break ;
175179 case UInt16 v :
176- max = JemUtil . ValToGenericStruct < ushort , TData > ( ( ushort ) ( ushort . MaxValue / ( ushort ) 4 ) ) ;
180+ max = Random ( ( ushort ) ( ushort . MaxValue / ( ushort ) 4 ) ) ;
177181 break ;
178- case Int64 v :
179- max = JemUtil . ValToGenericStruct < long , TData > ( ( long ) ( long . MaxValue / 4 ) ) ;
182+ case Int32 v :
183+ max = Random ( ( int ) ( int . MaxValue / 4 ) ) ;
184+ break ;
185+ case UInt32 v :
186+ max = Random ( uint . MaxValue / 4u ) ;
187+ break ;
188+ case Int64 v :
189+ max = Random ( ( long ) ( long . MaxValue / 4 ) ) ;
180190 break ;
181191 case UInt64 v :
182- max = JemUtil . ValToGenericStruct < ulong , TData > ( ulong . MaxValue / 4u ) ;
192+ max = Random ( ulong . MaxValue / 4u ) ;
183193 break ;
184194 case Double v :
185- max = JemUtil . ValToGenericStruct < double , TData > ( ( double ) ( long . MaxValue / 4 ) ) ;
195+ max = Random ( ( double ) ( long . MaxValue / 4 ) ) ;
186196 break ;
187197 case Single v :
188- max = JemUtil . ValToGenericStruct < Single , TData > ( ( Single ) ( long . MaxValue / 4 ) ) ;
198+ max = Random ( ( Single ) ( long . MaxValue / 4 ) ) ;
189199 break ;
190200 default :
191201 throw new ArithmeticException ( ) ;
192202 }
193- return new Tuple < TData , TData > ( JemUtil . ValToGenericStruct < int , TData > ( factor ) , JemUtil . ValToGenericStruct < int , TData > ( 20 ) ) ;
203+ return ( Const ( factor ) , Const ( max ) ) ;
194204
195205 }
196206 #endregion
0 commit comments