Showing posts with label Games. Show all posts
Showing posts with label Games. Show all posts

Sunday, December 15, 2024

What are some useful built-in functions of "Random" in Python?

 Random numbers are needed in most studies in information technology such as:

  • Simulation
  • Game Development
  • Machine Learning, AI, Image recognition
  • Cryptography
  • Code testing and many more.

Random module in Python has all the functions. You need to import Random to work with random functions in Python. Using this module you can generate random numbers and sequences. However, the random number generated are pseudo-random numbers, random numbers that are deterministic. In order to generate truly random numbers one has to resort to physical systems like noise, radioactive decay or weather related phenomenon.

Here is a brief description of the functions:

1. random.random():

Generates a random floating-point number between 0.0 (inclusive) and 1.0 (exclusive).

2. random.uniform(a, b):

Generates a random floating-point number between a and b, inclusive of a but exclusive of b.

3. random.randint(a, b):

Generates a random integer between a and b, inclusive of both a and b.

4. random.randrange(start, stop[, step]):

Generates a random integer from the range [start, stop), with an optional step value.

5. random.choice(seq):

Returns a random element from the sequence seq.

6. random.shuffle(x):

Shuffles the elements of the sequence x in place.

7. random.sample(population, k):

Returns a k length list of unique elements chosen from the population sequence or set.

Sequence is a general form of data structure that stores a collection of items in a specific order. It can be of different data types. In simple terms, an ordered list of same type of data is a sequence. 

Here is a better example of a sequence and a list:

Tuples (Immutable Sequences):

  • Ordered collection of elements.
  • Elements cannot be changed after creation.

Often used to represent fixed data structures.

Lists (Mutable Sequences):

  • Ordered collection of elements.
  • Elements can be modified, added, or removed.

More flexible for dynamic data structures.

===============

The random.shuffle(mylist) function modifies the list mylist in place and does not return a new list. This means that you need to have an existing list that you want to shuffle. The function directly changes the order of elements in the original list.

===============

Here is an example of the usage of the randum() function in PyCharm, Randoms.py. If you want use the code to run, remove space between each function shown below.

import random

# Generate a random float between 0 and 1
random_float = random.random()
print("Random Float: ", random_float)

# Generate a random integer between 1 and 10 (inclusive)
random_integer = random.randint(1, 25)
print("Random Integer: ", random_integer)

random_number_with_step = random.randrange(5, 67, 3)
# Generates a random integer from the range [start, stop), with an optional step value
print("Random Number with step: ", random_number_with_step)

random_choice_seq = random.choice([1, 200, 300, 412, 516])
# Returns a random element from the sequence (list as argument)seq.
print("Random Choice Sequence (list): ", random_choice_seq)

random_choice_seq=random.choice('A thing of beauty is a joy forever')
# Returns a random letter from the sequence (string as argument)seq
print("Random Choice Sequence (string): ", random_choice_seq)

random_shuffle_of_the_list=random.shuffle([1, 100, 1000, 10000])
#Shuffles the elements of the sequence x in place
print("Random Shuffle list in place: ", random_shuffle_of_the_list)


#random_Sample=random.sample(population, k)
#Returns a k length list of unique elements chosen from the population sequence or set.
# unlike random.shuffle, random.sample can accept a list variable or use list elements as argument

# Original list
my_list = [1, 100, 1000, 10000]
# Get a sample of 2 elements from the list
random_Sample_Population_k = random.sample(my_list, 2)
# Print a sampled list
print("Random_Sample_Population_k: ", random_Sample_Population_k)
------------------------------------------------------
Being random, each time you run the result will be different except the shuffle list
Random Float:  0.7630766884865164
Random Integer:  1
Random Number with step:  26
Random Choice Sequence (list):  412
Random Choice Sequence (string):  a
Random Shuffle list in place:  None
Random_Sample_Population_k:  [1, 1000]

Monday, July 15, 2024

What do BlueStacks, Genymotion, Nox and LDPlayer have in common?

 Bluestacks 10 (https://www.bluestacks.com/download.html)app player allows you to play mobile apps, both Cloud Gaming and Android Emulator) from the Google Play Store on your Windows or Mac computer. 

Genymotion (https://www.genymotion.com/product-desktop/download/)is a cross platform Android emulator for testing apps. It can do scalable testing that are done on virtual devices.It is available for windows (x64), Linux(x64) and macOS(x86-64, arm64) platforms as well as Genymotion SaaS and Genymotion Device Image.


Nox (https://www.bignox.com/) is yet another Android Emulator for playing mobile games.


 LDPlayer (https://www.ldplayer.net/) featured as the fastest Emulator for Android games PC.' 





Motivation:

Actually, I wanted the raw data on a commercial, low cost, smartwatch from a Chinese company that called upon an Android app called HBand. H Band is available on Google Play, but if you want to run it on your windows PC (Windows 11) you need an Android Emulator. All of the above apps are indicated for the use of H Band.

The Mobile app, H Band on a Android Phone works OK. But, what if you want to look at raw data of  (body temperature, step counts, blood pressure, blood glucose, blood oxygen, Heart rate,and body temperature) collected by the app.It is supposed to be a safe app as far as data safety is considered including transit time encryption). 


BlueStack:


I contacted BlueStack to find that it does not yet support Bluetooth.


I tried Nox to connect to the watch. It works sometimes and sometimes it does not open. All these apps run very slow, intolerable in this 5G era.

GenyMotion requires a virtualBox. I wanted something that would work with no additional software.

LDPlayer is another option and it takes a lot of memory. It's Bluetooth connection is also not good.





I looked up the space requirements for some of these and they do take up a lot of space and send non-stop notifications.

This is what one of the ChatGPT came up with:

1. **BlueStacks 5**:

   - RAM: Requires at least 4GB of RAM¹.

   - Storage: Approximately 5GB of free disk space².

   - CPU Consumption: Consumes about 10% CPU, making it efficient¹.

   - RAM Usage: Consumes the least amount of RAM compared to other emulators¹.


2. **LDPlayer**:

   - CPU Consumption: Registered a massive 145% higher CPU usage compared to BlueStacks¹.

   - RAM Usage: Consumes more RAM than BlueStacks¹.


3. **Nox**:

   - CPU Consumption: Consumes 37% more CPU resources with noticeable lag in-app performance¹.

   - Storage: Unfortunately, I couldn't find specific storage requirements for Nox, but it seems to take up significant space³.


4. **Genymotion**:

   - Genymotion is another popular emulator, but its resource usage can vary based on the specific configuration and usage.


I DECIDED TO DUMP THEM ALL AND USE THE ANDROID EMULATOR IN ANDROID STUDIO. WHAT IS MORE, I HAD USED IT YEARS AGO.

NOT BEING A GAMER, I DO NOT NEED THE PROGRAMS. WHen I FIND SOME TIME, I WILL GET RID OF THEM