문제

How does the TI-84 randInt function generate random numbers? I would like to replicate this PRNG on my computer so I can get some larger sample sizes, but I'm not sure how. Copying numbers 5 at a time from the calculator isn't an option. Running OS X 10.7.3

도움이 되었습니까?

해결책

I don't know of how to exactly replicate its function on a computer, however you do not have to generate only five numbers at a time. You can store very large random number samples in lists them transfer them via the ti connect software to your computer.

다른 팁

Based on my much more extensive answer here, the following is a C++ implementation of the Ti PRNG:

#include <iostream>
#include <iomanip>
using namespace std;

long mod1  = 2147483563;
long mod2  = 2147483399;
long mult1 = 40014;
long mult2 = 40692;
long seed1,seed2;

void Seed(int n){
  if(n<0) //Perform an abs
    n = -n;
  if(n==0){
    seed1 = 12345;
    seed2 = 67890;
  } else {
    seed1 = (mult1*n)%mod1;
    seed2 = n%mod2;
  }
}

double Uniform(){
  double result;
  seed1  = (seed1*mult1)%mod1;
  seed2  = (seed2*mult2)%mod2;
  result = (double)(seed1-seed2)/(double)mod1;
  if(result<0)
    result = result+1;
  return result;
}

double RandInt(int min, int max){
  if(min<max)
    return min+int((max-min+1)*Uniform());
  else
    return max+int((min-max+1)*Uniform());
}

int main(){
  Seed(0);
  for(int i=0;i<10;i++)
    cout<<setprecision(10)<<RandInt(5,97)<<endl;
}

I used a Ti-83 emulator to generate values for RandInt(5,97):

RandInt output

This matches the output of my program above:

$ ./a.out 
92
89
18
52
42
73
9
36
97
23
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top