//public static Bitmap RandomPixels(this Bitmap imgRandom) //{ // const int MAXPRIMERO = 19; // return imgRandom.RandomPixels(Convert.ToInt32(Math.Sqrt(imgRandom.Width) % MAXPRIMERO)); //} //public static Bitmap RandomPixels(this Bitmap imgRandom, int cuadradosPorLinea) //{ // //hay un bug y no lo veo... no hace cuadrados... // unsafe // { // imgRandom.TrataBytes((MetodoTratarBytePointer)((bytesImg) => // { // const int PRIMERODEFAULT = 13;//al ser un numero Primo no hay problemas // System.Drawing.Color[] cuadrados; // System.Drawing.Color colorActual; // int a = 3, r = 0, g = 1, b = 2; // int lenght = imgRandom.LengthBytes(); // int pixel = imgRandom.IsArgb() ? 4 : 3; // int pixelsLineasHechas; // int sumaX; // int numPixeles; // int posicionCuadrado = 0; // if (cuadradosPorLinea < 1) // cuadradosPorLinea = PRIMERODEFAULT; // else // cuadradosPorLinea = cuadradosPorLinea.DamePrimeroCercano(); // numPixeles = imgRandom.Width / cuadradosPorLinea; // numPixeles = numPixeles.DamePrimeroCercano(); // cuadrados = DamePixelesRandom(cuadradosPorLinea); // colorActual = cuadrados[posicionCuadrado]; // for (int y = 0, xMax = imgRandom.Width * pixel; y < imgRandom.Height; y++) // { // pixelsLineasHechas = y * xMax; // if (y % numPixeles == 0) // { // cuadrados = DamePixelesRandom(cuadradosPorLinea); // } // for (int x = 0; x < xMax; x += pixel) // { // if (x % numPixeles == 0) // { // colorActual = cuadrados[++posicionCuadrado % cuadrados.Length]; // } // sumaX = pixelsLineasHechas + x; // if (pixel == 4) // { // bytesImg[sumaX + a] = byte.MaxValue; // } // bytesImg[sumaX + r] = colorActual.R; // bytesImg[sumaX + g] = colorActual.G; // bytesImg[sumaX + b] = colorActual.B; // } // } // }) // ); // } // return imgRandom; //} #endregion private static IEnumerable <System.Drawing.Color> GetPixelesRandom(this int numPixeles) { for (int i = 0; i < numPixeles; i++) { yield return(System.Drawing.Color.FromArgb(MiRandom.Next())); } }
public static bool CanWrite(this DirectoryInfo dir) { bool canWrite = false; StreamWriter sw = null; string path = dir.FullName + Path.DirectorySeparatorChar + MiRandom.Next() + "Archivo.exTmp.SeTeniaDeHaberBorrado.SePuedeBorrar"; try { sw = new StreamWriter(path, false); sw.WriteLine("prueba"); canWrite = true; } catch { } finally { if (sw != null) { sw.Close(); if (File.Exists(path)) { File.Delete(path); } } } return(canWrite); }
private static int[] GetRandomDimensions() { int[] lenght = new int[MiRandom.Next(1, 10)]; for (int i = 0; i < lenght.Length; i++) { lenght[i] = MiRandom.Next(1, 15); } return(lenght); }
internal static Context <byte> Encrypt(Context <byte> context, byte[] password, int min, int max, LevelEncrypt level = LevelEncrypt.Normal, StopProcess stopProcess = null) { if (Equals(stopProcess, null)) { stopProcess = new StopProcess(); } else { stopProcess.Continue = true; } int randomTrush; int levelEncrypt = (int)level; for (; !context.Acabado && stopProcess.Continue; context.InputIndex++) { //pongo random randomTrush = CalculoTrash(context.InputIndex, password, levelEncrypt); for (int i = 0; i < randomTrush; i++) { context.Output[context.OutputIndex] = (byte)MiRandom.Next(min, max); context.OutputIndex++; } //pongo data context.Output[context.OutputIndex] = context.Input[context.InputIndex]; context.OutputIndex++; } if (!context.Acabado && stopProcess.Continue) { //pongo random para tapar el último byte randomTrush = CalculoTrash(context.InputIndex, password, levelEncrypt); for (int i = 0; i < randomTrush; i++) { context.Output[context.OutputIndex] = (byte)MiRandom.Next(min, max); context.OutputIndex++; } } return(context); }
public static IEnumerable <int> GetRandomPositionList(this int total, int start = 0) { if (total < 0 || start < 0 || start > total) { throw new ArgumentOutOfRangeException(); } int posicionRandom; List <int> posList = new List <int>(); for (int i = start; i < total; i++) { posList.Add(i); } for (int i = start; i < total; i++) { posicionRandom = MiRandom.Next(0, posList.Count); yield return(posList[posicionRandom]); posList.RemoveAt(posicionRandom); } }
public void TestSetAndGetValue() { const int LADO = 5; int[,] matriz = new int[LADO, LADO]; int[] dimensiones = { LADO, LADO }; bool correcto = true; for (int i = 0, y = 0, yF = LADO, xF = LADO; y < yF && correcto; y++) { for (int x = 0; x < xF && correcto; x++, i++) { Gabriel.Cat.S.Extension.ExtensionArray.SetValue(matriz, dimensiones, i, MiRandom.Next(int.MaxValue)); correcto = matriz[x, y] == (int)Gabriel.Cat.S.Extension.ExtensionArray.GetValue(matriz, dimensiones, i); } } Assert.IsTrue(correcto); }
public void TestSetAnyValue() { int[] dimensions = GetRandomDimensions(); Array array = Array.CreateInstance(typeof(int), dimensions); for (int i = 0, f = array.Length; i < f; i++) { Gabriel.Cat.S.Extension.ExtensionArray.SetValue(array, dimensions, i, MiRandom.Next(1, 200)); } }
/// <summary> /// Prepara la partida per començar /// </summary> public void PartidaNova() { int[] aux = null; for (int i = 0; i < subministraments.Count; i++) { if (subministraments.GetKey(i) != nameof(Jardins)) { subministraments.SetValueAt(i, 10); } else { subministraments[nameof(Jardins)] = Jugadors.Length > 2 ? 12 : 8; } } subministraments[nameof(Malediccio)] = Jugadors.Length == 2 ? 10 : Jugadors.Length == 3 ? 20 : 30; subministraments[nameof(Provincia)] = Jugadors.Length > 2 ? 12 : 8; subministraments[nameof(Ducat)] = Jugadors.Length > 2 ? 12 : 8; subministraments[nameof(Finca)] = Jugadors.Length > 2 ? 12 : 8; subministraments[nameof(Or)] = 30; subministraments[nameof(Plata)] = 40; subministraments[nameof(Coure)] = 60; for (int i = 0; i < Jugadors.Length; i++) { Jugadors[i].Reset(); jugadorActual = i; for (int j = 0; j < 7; j++) { AgafaCarta(typeof(Coure)); } for (int j = 0; j < 3; j++) { AgafaCarta(typeof(Finca)); } } Eliminades.Clear(); Jugada.Clear(); DinersExtra = 0; if (guanyadorsPartidaAnterior.Count == 0 || guanyadorsPartidaAnterior.Count == Jugadors.Length) { jugadorActual = MiRandom.Next(Jugadors.Length); } else if (guanyadorsPartidaAnterior.Count == 1) { jugadorActual = guanyadorsPartidaAnterior[0]; AvançaJugador(); } else if (guanyadorsPartidaAnterior.Count == 3 && Jugadors.Length == 4) { jugadorActual = QuatreJugadors.Except(guanyadorsPartidaAnterior).First(); } else { if (Jugadors.Length == 4) { aux = QuatreJugadors; } else if (Jugadors.Length == 3) { aux = TresJugadors; } aux = aux.Except(guanyadorsPartidaAnterior).ToArray(); aux.Desordena(); jugadorActual = aux[0]; } }