"set RNG(RandomUtils.Random) before generating random numbers" error

0 votes

I am learning to program blockchain and i am using the code:

static void Main(string[] args)
{
    try
    {
        Key privateKey = new Key(); // generate a random private key
        PubKey publicKey = privateKey.PubKey;
        Console.WriteLine(publicKey); // 0251036303164f6c458e9f7abecb4e55e5ce9ec2b2f1d06d633c9653a07976560c

        Console.WriteLine(publicKey.GetAddress(Network.Main)); // 1PrBDFfAiwqxe2izPcTsj5t4Dn5pjbvtH6
        Console.WriteLine(publicKey.GetAddress(Network.TestNet)); // n3zWAo2eBnxLr3ueohXnuAa8mTVBhxmPhq

        var publicKeyHash = publicKey.Hash;
        Console.WriteLine(publicKeyHash); // f6889b21b5540353a29ed18c45ea0031280c42cf
        var mainNetAddress = publicKeyHash.GetAddress(Network.Main);
        var testNetAddress = publicKeyHash.GetAddress(Network.TestNet);

        Console.WriteLine(mainNetAddress); // 1PrBDFfAiwqxe2izPcTsj5t4Dn5pjbvtH6
        Console.WriteLine(testNetAddress); // n3zWAo2eBnxLr3ueohXnuAa8mTVBhxmPhq

        Console.ReadLine();
    }
    catch (Exception)
    {    
        throw;
    }   
}


and when i run this, i get the following error pointing to the first line:

You must set the RNG (RandomUtils.Random) before generating random numbers

I know i have to set RNG as the error suggests but how do i do it?

Jul 5, 2018 in Blockchain by digger
• 27,620 points
25 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
Use the following code, you just have to initialize the generator and it will solve your problem.

RandomUtils.Random = new UnsecureRandom(); // this sets the random number generator
Key privateKey = new Key(); //this generates random private key
answered Jul 5, 2018 by slayer
• 29,040 points

Related Questions In Blockchain

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Error in generating network sample.

I resolved this issue by downloading the ...READ MORE

answered Jul 26, 2018 in Blockchain by Perry
• 16,450 points
27 views
0 votes
1 answer
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 27,620 points
38 views
+1 vote
1 answer
0 votes
1 answer

JavaFX Location is not set error message

I had this problem and found this ...READ MORE

answered Sep 19, 2018 in Blockchain by slayer
• 29,040 points
348 views
0 votes
1 answer

Error connecting due to rpc error

In the previous version, this problem was ...READ MORE

answered Jul 6, 2018 in Blockchain by slayer
• 29,040 points
119 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.