Estoy generando números random sin repetir en Visual Basic .Net ¿Cómo hago para que el cero no me quede de ultimo?

Estoy generando números random sin repetir en Visual Basic .Net, pero al final de todos los números generados siempre me queda el cero, ¿cómo hago para que cero cambie de posición al generar los números random?

While (numero_elementos < 7)         aleatorio = numAleatorioEntre(0, 7)         encontrado = False           For i = 0 To 7 And Not encontrado             If (aleatorio = numeros(i)) Then                 encontrado = True             End If         Next          If (encontrado = True) Then             Console.WriteLine("El numero existe: " & aleatorio)         Else             numeros(numero_elementos) = aleatorio             numero_elementos = numero_elementos + 1             Console.WriteLine("Agregado el numero: " & aleatorio)         End If      End While          Console.WriteLine("Mostrar arreglo")     For i = 0 To 7         Console.WriteLine(numeros(i))     Next 

conditional probability of dependent random variables

Suppose I have 3 random variables:

$ $ X \sim \mbox{Bernoulli}(1/2)$ $ $ $ Z \sim \mbox{Normal}(0,1)$ $ $ $ Y = X+Z$ $

How do I compute the conditional probability:

$ $ P(X=1 | Y=y)$ $


Probability[ X == 1 \[Conditioned] X + Z == y,             {             X \[Distributed] BernoulliDistribution[1/2]            ,Z \[Distributed] NormalDistribution[]            }          ] 


D[Probability[ X == 1 \[Conditioned] X + Z >= y,             {             X \[Distributed] BernoulliDistribution[1/2]            ,Z \[Distributed] NormalDistribution[]            }          ],y] 


Likelihood[       TransformedDistribution[X + Z,                     {                     X \[Distributed]BernoulliDistribution[1/2],                     Z \[Distributed] NormalDistribution[]}]            , {y}] 

Pencil and Paper attempt:

$ $ P(X=1 | Y=y) = \frac{P(X=1 , Y=y)}{P(Y=y)}$ $ $ $ = \frac{P(X=1 , X+Z=y)}{P(Y=y)}$ $ $ $ = \frac{P(X=1)P(Z=y-1)}{P(Y=y)}$ $ $ $ = \frac{P(X=1)P(Z=y-1)}{P(X=1)P(Z=y-1)+P(X=0)P(Z=y-0)}$ $

$ $ P(Z=y)=\frac{e^{-\frac{y^2}{2}}}{\sqrt{2 \pi }}$ $ $ $ P(Z=y-0)=\frac{e^{-\frac{y^2}{2}}}{\sqrt{2 \pi }}$ $ $ $ P(Z=y-1)=\frac{e^{-\frac{1}{2} (y-1)^2}}{\sqrt{2 \pi }}$ $ $ $ P(X=1)=\frac{1}{2}$ $ $ $ P(X=0)=\frac{1}{2}$ $

$ $ P(X=1 | Y=y) = \frac{e^{-\frac{1}{2} (y-1)^2}}{2 \sqrt{2 \pi } \left(\frac{e^{-\frac{y^2}{2}}}{2 \sqrt{2 \pi }}+\frac{e^{-\frac{1}{2} (y-1)^2}}{2 \sqrt{2 \pi }}\right)}$ $

$ $ P(X=1|Y=y) = \frac{e^y}{e^y+\sqrt{e}}$ $

Ordered data structure with efficient push, iteration and random pop/drain

I need a data structure d with somewhat conflicting requirements. What are the different tradeoffs I could pick?

The same algorithm will be repeatedly done on each time step:

  • push one new element to the right (so all elements remain naturally ordered by the date they came into the data structure).
  • update all elements. I mean iterate (in any order or parallel) and mutate in place.
  • based on the result of the update, drain random elements in order (new or old). I mean that some will have to be both returned in order to user and removed from d.
  • user should also easily iterate in order over remaining elements.

For instance, think of a bunch of fruit that takes a random time to ripen. One new piece of fruit is spawned each day. And each day we need to collect (ordered) ripe fruit, while keeping remaining pieces of fruit ordered by age.

Is there a dedicated data structure?
If not, is there a pattern for this case?
If not, what are the different tradeoffs I’ll have to deal with? Is there any assumption I could make on the data (like drain frequency) to help me choose?
(for instance, I suspect that many pieces of fruit will be ripe on the first or the first few update(s), and only a few will last longer)

Criando um objeto com um dado interno randômico (random)

Estou tentando criar um objeto chamado “Estado”, no entanto gostaria que o DDD de cada objeto, ao criar, fosse gerado aleatoriamente.

class Estado {     public int Resultado { get; set; }     public string Nome { get; set; }      public Estado(string nome)     {         Nome = nome;         rnd();     }     public void rnd()     {         Random random = new Random();         Resultado = random.Next(0, 101);     }     public override string ToString()     {         return "Estado: "+Nome+"\nDDD: "+Resultado;     } } 

Mas ao rodar:

 static void Main(string[] args)     {         Estado pe = new Estado("Pernambuco");         Estado pa = new Estado("Pará");         Estado pi = new Estado("Piauí");         Estado pr = new Estado("Paraná");          Console.WriteLine(pe.ToString());         Console.WriteLine(pa.ToString());         Console.WriteLine(pi.ToString());         Console.WriteLine(pr.ToString());         Console.ReadLine();     } 

O resultado saí repetido:

Estado: Pernambuco

DDD: 60

Estado: Pará

DDD: 60

Estado: Piauí

DDD: 60

Estado: Paraná

DDD: 60

Como posso fazer para cada objeto, ao criar o construtor, ter seu próprio DDD gerado aleatoriamente?

Magento 2.2 Random frontend display issues and 500 error reports

We are running a large Magento site (17 store views) with several custom modules installed.

Most of the time the sites are stable and performing well, however, we do get some random issues where the skinning on the sites fails to apply in the frontend, and have seen occasions where backend can lose formatting, or even return 500 error.

When these happen, cache cleaning usually solves the problem. Does anyone know of potential causes, and preventative measures?

We are using the in-built caching, rather than Varnish.

Is it possible to transfer data with a really unique seed of a psudo random number generator

I have thinking about this idea for over 5 years and i don’t have the complete technical knowledge to fully grasp the idea I’m having.

The premise of the idea is to have an extremely high base number system like base 85 / Ascii85.

Then use that high base number to express an extremely verbose seed for a pseudo random data generator.

Then using your data generator, generate out data to a specified length of characters.

The business case for this would hopefully be a way of transferring data in an extremely compressed format that is actually just a function expression of how to calculate out your large set of data.

So for example if you want to move 10 gigabytes of data, you somehow serialize that 10 gigabytes down into a random seed that propagates back out into the same 10 gigabytes again.

The reason for something like Ascii85 is so that you could express a high amount of unique permutations.

This idea is probably completely crazy and or incorrect, but i have wondered about it for so long i really wanted some advice on it.

Substance Designer: How to target the corners of random tiles

I’m trying to figure out a way to target the corners of randomly generated tiles so that I can place details there. Take for example putting bolts at every corner of a series of metal plates, for example. You want the bolts to be a consistent distance from the corner, and not to be skewed.

enter image description here

I have been able to create the following effect by a series of combined blurs, so this is generated just from the tile grid.

enter image description here

Here is the method: enter image description here

But this couldn’t really be used to actually place any complex designs in the same locations. How would I go about placing more complex details in those same locations?

Probability of sum of 2 random dice out of a 3d6 pool

With AnyDice it’s pretty easy to calculate probalities for highest and lowest 2 of a 3d6 pool, namely with:

output [highest 2 of 3d6] output [lowest 2 of 3d6] 

However, this has a bias towards the highest and lowest thrown dice. What I want to calculate is the possible results, without bias. Reasoning behind this is that I want my players to control the outcome. It’s not necessarily that the highest or lowest outcome are worse or better, it’s simply that I want to offer them a decision. They choose two of the dice, add them together and there is a result. I want to give the luck d20 roll with result such as an encounter more meaning and mental impact (“why did you pick those dice!”).

I had hoped AnyDice to have a random function, something like [random 2 of 3d6] but that doesn’t exist. My hypothesis was that I could simply add the percentages of [highest 2 of 3d6] and [lowest 2 of 3d6] and divide that number by 2 (since I’m adding two probability calculations with a total of 100%).

But somehow this doesn’t feel right. It doesn’t include the possibility of a player picking the highest and the lowest number instead of the two highest or lowest.

I’ve been doing some tutorials in AnyDice and I reckon this definitely CAN be done with a function where the following would happen:

Roll 3d6. Then also roll a d3 twice (not 2d3 as it would add up). If the d3 rolls are equal, reroll one until you get two unique d3 rolls. Then use the unique d3 rolls and take those dice from the 3d6 pool. Add those dice together, show results. 

An approach of this chance could be that I take simply the average of a single die in the 3d6 pool and then multiply by 2, theoretically approaching all the possible results. This is incorrect as well as it includes all three dice and thus the average can go higher than the max of 2d6.

Perhaps I’m overthinking this calculation by using AnyDice. As the the dice order isn’t relevant at all, I simply need to know all possible dice combinations a 3d6 pool can have. Not the sum, but the combinations. This is super simple, because every dice has 6 sides. So 3d6 has 6 * 6 * 6 = 216 total combinations, this includes repetition as I am interested in the probability of each throw. However, I again don’t need all three dice. Only 2, which for the sake of calculation can be presumed to be picked randomly.

Another option I can think of in AnyDice is:

Roll 3d6 and 1d3. Remove from 3d6 sequence the number in position 1d3. Add the remaining sequence's result and output probabilities. 

Okay, long wall of text, but I am just not familiar enough with AnyDice to figure this out. Any help is greatly appreciated.

Generate random matrix and its inverse

I want to randomly generate a pair of invertible matrices $ A,B$ that are inverses of each other. In other words, I want to sample uniformly at random from the set of pairs $ A,B$ of matrices such that $ AB=BA=\text{Id}$ .

Is there an efficient way to do this? Can we do it with expected running time approaching $ O(n^2)$ ?

Assume we are working with $ n\times n$ boolean matrices (all entries 0 or 1, arithmetic done modulo 2). I am fine with an approximate algorithm (say, it samples from a distribution exponentially close to the desired distribution). My motivation is solely curiousity; I have no practical application in mind.

The obvious approach is to generate a random invertible matrix $ A$ , compute its inverse, and set $ A=B^{-1}$ . This has running time $ O(n^\omega)$ , where $ \omega$ is the matrix multiplication constant — something in the vicinity of $ O(n^3)$ in practice. Can we do better?

An approach that occurred to me is to choose a set $ T$ of simple linear transformations on matrices such that, for each $ t \in T$ , we can apply the modifications $ M \mapsto tM$ and $ M \mapsto Mt^{-1}$ in $ O(1)$ time. Then, we could set $ A_0=B_0=\text{Id}$ , and in step $ i$ , sample a random $ t$ from $ T$ , set $ A_{i+1}=tA_i$ and $ B_{i+1}=B_it^{-1}$ , and repeat for some number of steps (say $ O(n^2 \log n)$ iterations). However I’m not sure how we would prove how quickly this approaches the desired distribution.