random - Keep getting 0 as an output in C# division -


i'm trying divide random number generated 13. can range 1, 53. need divide random number 13 whole number (to determine suit in deck of cards). need suit out of 1-4.

random number:

value = myrandom.next(1, 53); 

division:

suit = value / 13; face = value % 13; 

the suit keeps generating 0 way.

i'm going take stab in dark you're asking.

i'm guessing you're getting non-zero values suit, you're getting zero. main issue here, in case, boils down 0-based vs 1-based indexing.

what need do generating/computing 0-based indexing, , add 1 shift 1-based indexing. (alternatively, use 0-based indexing)

example code:

value = myrandom.next(0, 52); // notice values inclusively between 0 , 51 suit = (value / 13) + 1; // between 1 , 4 face = (value % 13) + 1; // between 1 , 13 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -