Do not use Random

This commit is contained in:
nicolas.dorier 2021-03-23 17:53:23 +09:00
parent 1fc114fec7
commit af9d896510
No known key found for this signature in database
GPG key ID: 6618763EF09186FE
2 changed files with 2 additions and 4 deletions

View file

@ -350,13 +350,12 @@ namespace BTCPayServer.Payments.PayJoin
&& feeOutputIndex < newTx.Outputs.Count
&& !isOurOutput.Contains(newTx.Outputs[feeOutputIndex])
? newTx.Outputs[feeOutputIndex] : null;
var rand = new Random();
int senderInputCount = newTx.Inputs.Count;
foreach (var selectedUTXO in selectedUTXOs.Select(o => o.Value))
{
contributedAmount += (Money)selectedUTXO.Value;
var newInput = newTx.Inputs.Add(selectedUTXO.Outpoint);
newInput.Sequence = newTx.Inputs[rand.Next(0, senderInputCount)].Sequence;
newInput.Sequence = newTx.Inputs[(int)(RandomUtils.GetUInt32() % senderInputCount)].Sequence;
}
ourNewOutput.Value += contributedAmount;
var minRelayTxFee = this._dashboard.Get(network.CryptoCode).Status.BitcoinStatus?.MinRelayTxFee ??

View file

@ -52,11 +52,10 @@ namespace BTCPayServer.Security.Bitpay
// It is legacy support and Bitpay generate string of unknown format, trying to replicate them
// as good as possible. The string below got generated for me.
var chars = "ERo0vkBMOYhyU0ZHvirCplbLDIGWPdi1ok77VnW7QdE";
var rand = new Random(Math.Abs(RandomUtils.GetInt32()));
var generated = new char[chars.Length];
for (int i = 0; i < generated.Length; i++)
{
generated[i] = chars[rand.Next(0, generated.Length)];
generated[i] = chars[(int)(RandomUtils.GetUInt32() % generated.Length)];
}
using (var ctx = _Factory.CreateContext())