Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Last active April 21, 2025 13:24
Show Gist options
  • Save Strelok78/654149a1b807ffce8e4b3a53422ff8f1 to your computer and use it in GitHub Desktop.
Save Strelok78/654149a1b807ffce8e4b3a53422ff8f1 to your computer and use it in GitHub Desktop.
get power of two that bigger then random value (without Math.Pow operations)
using System.Diagnostics;
namespace iJuniorPractice;
class Program
{
static void Main(string[] args)
{
Random random = new Random();
int baseDegree = 2;
int multipleTemporaryValue = 1;
int randomValue = random.Next();
int powerValue = 0;
randomValue = 8;
while (multipleTemporaryValue <= randomValue)
{
multipleTemporaryValue *= baseDegree;
powerValue++;
}
Console.WriteLine("random value = {0}, power value = {1}, value = {2}, base degree = {3}", randomValue, powerValue, multipleTemporaryValue, baseDegree);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment