dimanche 2 juin 2019

Roblox script - random trap activation

I am doing a map and part of it player will have to decide which of let say 3 steps to step on. 1 is OK and will let them pass and others will kill them.

What I am trying to do is to make random activation to ensure each game start with different step being the safe one.

I tried._G to randomly chose number 1-3 and depending on the number step 1,2 or 3 would be the safe one and the other one would be activated kill script. But this never worked.

There is option to clone map and alter manually steps and just random map at start but this seems counterproductive.

Is there a way to make function choose random number at start of the game (random seed) and depending on the number picked in main script (in workplace or other place?) other local scripts can read this number and decide if part is a killing trap or just a brick?

This would allow me to use one number chosen to determine possible other parts of the game. So the player don't get to remember safe way to pass each time they enter the game.




Generate Random Number from Bits

I have the following method which generates random bits:

private byte generateRandomBit()
{
    long randNum = (long) Math.Pow(Seed, 2) % M;
    Seed = randNum;
    if((Seed % 2) == 0)
    {
         return 0;
    }
    else
    {
         return 1;
    }
}

Now, I have another method that generates the next random number using the above method. I searched and found some answers, though they were not applicable to mine. Can anyone help me go around this please?




Generate a Random Bit using Blum Blum Shub Algorithm

I am doing a program which asks the user for an amount of numbers (X), the least number (L) and the maximum number (M) and it generates X random numbers, between L and M. Now, one of the methods used is to generate a random bit using blum blum shub algorithm. I searched everywhere, with no luck. How can I generate a random bit using this algorithm please?

Thanks!




samedi 1 juin 2019

How can I use two random numbers generated in a function as matrix coordinates?

I came up with this function to generate two random numbers, r and c, so that I can use them in as coordinates in matrix board[r][c]. Is this even possible?

This is for a chess-like game. The PC is supposed to generate random moves. This function does generate coordinates, I'm just not sure how to make my program treat them as coordinates.

int coordAleatoria()

I hope I can get r and c in board[r][c] to be the values generated in coordAleatoria().




C++ Generate a random prime using GMP library

I was looking into GMP documentation. I couldn't find any function for generating random prime of given length. One simple way to do it is:

while true
{
     mpz_urandomb(sampled_value, random_state, length);
     if (!mpz_probab_prime_p(sampled_value, 50))
          break;
}

I was wondering if there is more efficient GMP library function to sample random prime of given length. I would like to sample many random primes. Is there a function that does this more efficiently than sampling each of them in a loop.




How to use np.random.rand(1) in Pandas to generate a number between 2 values?

I understand that you can generate a number using np.random.rand(1) and then by multiplying this by a factor, but how can I generate a number within a range, say from 1 to 4.

Thanks




How to generate 4 different random numbers in C++

I am making Bulls and Cows assignment from Bjarne Stroustrup's "Programming Principles and Practice Using C++" book (p. 130, exercise 13) and I want program to generate four different integers in the range 0 to 9 (e.g., 1234 but not 1122)

I made a vector to store numbers and a function which generates 4 numbers and adds them to vector, but numbers might be the same and I can't return numbers to main function

#include "../..//..//std_lib_facilities.h"

vector<int> gen4Nums(vector<int> secNum)
{
    random_device rd; // obtain a random number from hardware
    mt19937 eng(rd()); // seed the generator
    uniform_int_distribution<> distr(0, 9); // define the range 

    secNum.clear();
    for (int i = 0; i < 4; i++)
    {
        secNum.push_back(distr(eng));
        cout << secNum[i];
    }
    return secNum;
}

int main()
{
        vector<int> secNum;
        gen4Nums(secNum);   
}

I expect to return 4 different random numbers to the main function