Questions tagged [lcg]

A linear congruential generator (LCG) is an algorithm that yields a sequence of pseudo-randomized numbers calculated with a discontinuous piecewise linear equation.

The linear congruential generator LCG is defined by recurrence relation:

    equation

where:
    X is the sequence of pseudo-random values
    m is the modulus (m > 0)
    a is the multiplier (0 < a < m)
    c is the increment (0 <= c < m)
    X0 is the "seed" or start value (0 <= X0 < m)

45 questions
0
votes
1 answer

Code for reversing Linear Congruential Generator in python

index 0 of x is the seed, but what if, you want to know the index -1 of x. I am making a game in python with pygame, and i require help, since i require to use that in world generation Edit: x is the random number, index 0 of x is seed the LCG looks…
Radiant
  • 31
  • 4
0
votes
1 answer

Output Argument Not Assigned During Call: Matlab

I am attempting to generate 2500 psuedo-random numbers using LCG for a project. However, when I attempt to run the code I continuously receive the error "Output argument 'p' (and maybe others) not assigned during call to lcgg'.". I was hoping…
TryingToMath
  • 13
  • 1
  • 2
  • 6
0
votes
2 answers

Python: Not Returning Value From Linear Congruential Generator Function

I am attempting to make a randomly generated plot using the LCG method. While the plot behavior works, my issue is when I attempt to return a list to a variable. My goal is to have the recursive function return a list to a variable, but it seems…
Apple Cola
  • 27
  • 2
  • 9
0
votes
0 answers

How can I get the seed from the result of a LCG generator in Lua?

I'm currently working on a Lua port of the Library Of Babel. To my knowledge, it works by randomly generating the title and book by using the Hex, Bookshelf, Shelf, and Volume numbers. To implement this in Lua, I was using randomlua, because Lua's…
0
votes
2 answers

Floating point exception (core dumped) for Linear Congruential Generator

I'm finishing up my header file for a Linear Congruential Generator (LCG) based cipher program. It receives two unsigned long values (m and c) and generates the LCG struct using these values. In my getA() I'm trying to have it add the temp variable…
0
votes
0 answers

How do I generate (x,y) coordinates with this multiplicative LCG?

I developed the following code in Java: /** * Método que sirve como generador lineal con unos parámetros dados. * @param multiplier multiplicador de la seed dada. * @param seed semilla inicial del programa; indicará en que punto del periodo…
0
votes
0 answers

Tests for Linear Congruential Generator in Python

What tests should be performed for this LCG in python? Everything that comes to my mind is: Diehard, chi-square, kol-smirnov and that's obviously enough for my purposes (its a homework) but I have read some articles and documentation about these…
tbone
  • 1,148
  • 5
  • 19
  • 35
0
votes
1 answer

How to use Linear congruential generator

I have to develop a Linear Congruential Generator with this formula Xn+1 = (aXn + b) mod m in Python. I think I understand how to generate the sequence of numbers but I don't know how to use it, for example to simulate a dice (I need a number…
J.doe
  • 37
  • 6
0
votes
1 answer

Why doesn't my math add up in my LCG?

For example here: http://www.math.cornell.edu/~mec/Winter2009/Luo/Linear%20Congruential%20Generator/linear%20congruential%20gen1.html I am trying to implement an LCG for an example problem set, but it's not working for me and I cant seem to figure…
Brian Jackson
  • 409
  • 1
  • 5
  • 16
0
votes
1 answer

Analysis of Linear congruential generator is wrong?

So in an attempt to better understand MSVC++'s implementation of rand, I re-implemented it and attempted to better understand it (and LCGs in general I guess). My implementation (which matches MSVC++'s almost exactly) is as follows: // vc++ impl. of…
Matthew
  • 268
  • 1
  • 11
0
votes
0 answers

Predicting the outcome of PHP rand() function given a seeded value

Recently I've been getting into the whole idea of LCGs and Pseudorandom number generators. Anyway, I though that PHP should be a good starting point. My question is, given a seeded number (done through srand() ) how does one predict the next number…
Redseb
  • 199
  • 10
0
votes
1 answer

Generate multiple draws (calls) of a given method in java (simulated lottery)

I received the task of simulating a lottery draw in java. The program skeleton yields the method generateOneDraw, which creates 6 random numbers between 1 and 49 static int[] generateOneDraw() { int numbers[] = new…
Nina Hain
  • 41
  • 1
  • 2
  • 8
0
votes
0 answers

LCG create method to set a subset of all properties in class (reflection substitute; c#)

Scenario: I have this class public class Person { public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } } User has the ability to only select for example FirstName and Age. Currently I…
Gustavo
  • 685
  • 3
  • 7
  • 17
-1
votes
1 answer

What does *&Var - 1.0f means?

Working with some tutorial, I met a strange C++ expression: uint64_t var = .... return (*&var) - 1.f; What does this mean? Is it a reference to a pointer? What's the point of substracting 1 from reference? It should be an implementation of the LCG…
zealot
  • 53
  • 5
-1
votes
1 answer

Mismatch in integer calculation results between C++ and Python (random number generator)

I needed a pseudo random number generation scheme (independent of standard libraries) for one of my projects and I tried a simple LCG based RNG. It seems to work fine except that it produces different values in C++ and Python. I am giving the…
Axeon Thra
  • 334
  • 3
  • 14
1 2
3