1

だから私はarc4randomを使ってforumlaに乱数ジェネレーターを組み込んでいます。したがって、forumlaには3つの変数があります

Variable 1 > User enters it
Variable 2 > User enters it
Variable 3 > arc4random

私の質問は、変数1と2が同じである場合、arc4randomに同じ番号を作成するように指示するにはどうすればよいですか?

So if
V1 = 5
V2 = 4
V3 = 68 and the user enters 5&4 it shall create 68 again, BUT after 10 minutes it may use another random number

Sryはそれをコードとして配置する必要がありました。それ以外の場合は、この質問をアップロードできなかったからです。

4

1 に答える 1

0

これは私が理解したことです:あなたは2つの数字ともう1つをarc4randomによって生成するように依頼したいのですが、ユーザーが次の10分間に同じ2つの数字を導入する場合、arc4randomの数字は等しくなければなりません。

他の変数(たとえば、saveV1、saveV2、saveV3)に数値を保存し、600秒の時間間隔でNSTimerを起動しようとします。NSTimerのセレクターは、saveVX変数をクリーンアップします。つまり、これが構造です。

    1. Ask V1 
    2. Ask V2
    3. Check if there are saved numbers and check if they are V1 == saveV1 and V2 == saveV2
    4A. If they are the same: V3 = saveV3 
    4B. If they aren't: Generate V3
    5. Save V1, V2, V3 in saveV1, saveV2 and saveV3.

これはあなたが求めていたものですか?

編集済み:コードは次のとおりです。

//v1, v2, v3, saveV1, saveV2, saveV3 declared in the .h file
-(void) function
{
  v1 = [[v1TextField text] intValue];
  v2 = [[v2TextField text] intValue];

if(v1 == saveV1 && v2 == saveV2) 
{
  v3 = saveV3;
}
else
{
  v3 = arc4random()%100; //This line generates a random number between 0 and 99.
  [NSTimer scheduledTimerWithTimeInterval:600.0f target:self selector:@selector(deleteVs)   userInfo:nil repeats:NO];
}

saveV1 = v1;
saveV2 = v2;
saveV3 = v3;

NSLog(@"V1: %d, V2: %d, V3: %d",v1,v2,v3);

}

-(void)deleteVs
{
saveV1 = 0;
saveV2 = 0;
saveV3 = 0;
//You can change this and put -1 to have 0 as a valid value of v1 and v2.
}
于 2012-07-22T00:11:01.787 に答える