Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7868283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:57:06+00:00 2026-06-03T00:57:06+00:00

I am making a small class for a little project. It’s a text based

  • 0

I am making a small class for a little project. It’s a text based RPG game and I am trying to create a drop class for when NPC’s die. I have create a couple Math.random methods (which are exactly the same, just differently named for my convenience.) to drop random amounts for an item id (name) and to get the rarity of the item dropped. It all works fine, but it only randomizes one time (on startup or run) and it won’t randomize the amounts after that. I am also randomizing it between 2 numbers, for example, 25 and 50, the random not going lower then 25 or higher then 50.

My question is: How can I randomize a integer in a 2D Array or a general array after each time a NPC dies, so the random number that is first obtained changes and doesn’t stay the same. Because right now, it stays at the number choose. if the number is 25, then the next npc I kill, the amount would still be 25.. and 25.. and 25.. and so on. I need it to randomize or change.

Please help, thank you.

   public class DropConfig {

    private static final int
        ALWAYS = 0,
        VERY_COMMON = rate(1, 9),
        COMMON = rate(10, 20),
        UNCOMMON = rate(30, 40),
        RARE = rate(50, 60),
        VERY_RARE = rate(70, 80),
        SUPER_RARE = rate(90, 100);

    public static final int[][] NPC_DROPS = {

        // Normal NPC's
        {1, 526, 1, ALWAYS}, 
        {2, 526, 1, ALWAYS}, 
        {3, 526, 1, ALWAYS}, 
        {1, 995, drop(1, 50), ALWAYS}, 
        {2, 995, drop(1, 50), ALWAYS},
        {3, 995, drop(1, 50), ALWAYS},

        // Moderate NPC's
        {9, 526, 1, ALWAYS}, 
        {9, 995, drop(250, 500), UNCOMMON},
        {9, 555, drop(2, 7), VERY_COMMON},
        {9, 995, drop(5, 50), VERY_COMMON},
        {9, 1050, 1, RARE}, 
    };

    public static int rate(int min, int max) {
        return 1 + (int)(Math.random() * ((max - min) + 1));
    }

    //Same as rate, different name for looks.
    public static int drop(int min, int max) {
        return 1 + (int)(Math.random() * ((max - min) + 1));
    }

Heres where I call the drops method

public void npcDeath() {
    int npc = 0;    
    if (npc == null)
        return;
    for(npc = 0; npc < DropConfig.NPC_DROPS.length; npc++) {
        if(npc == DropConfig.NPC_DROPS[npc][0]) {
            if(Misc.random(DropConfig.NPC_DROPS[npc][3]) == 0) { //Drops ALWAYS item
                Item(DropConfig.NPC_DROPS[npc][1], DropConfig.NPC_DROPS[npc][2]);
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:57:07+00:00Added an answer on June 3, 2026 at 12:57 am

    If I understand correctly, you would like the elements of the NPC_DROPS array initialized with a call to drop() to be reinitialized each time this NPC_DROPS array is used.

    Well, NPC_DROPS is a constant, so it can’t change. Generate it each time it’s accessed, using a method:

    public static int[][] generateNpcDrops(){
        return new int[][] {
    
        // Normal NPC's
        {1, 526, 1, ALWAYS}, 
        {2, 526, 1, ALWAYS}, 
        {3, 526, 1, ALWAYS}, 
        {1, 995, drop(1, 50), ALWAYS}, 
        {2, 995, drop(1, 50), ALWAYS},
        {3, 995, drop(1, 50), ALWAYS},
    
        // Moderate NPC's
        {9, 526, 1, ALWAYS}, 
        {9, 995, drop(250, 500), UNCOMMON},
        {9, 555, drop(2, 7), VERY_COMMON},
        {9, 995, drop(5, 50), VERY_COMMON},
        {9, 1050, 1, RARE}, 
        }
    }
    
    ...
    
    public void npcDeath() {
        int npc = 0;    
        if (npc == null)
            return;
        int[][] npcDrops = DropConfig.generateNpcDrops();
        for(npc = 0; npc < npcDrops.length; npc++) {
            if(npc == npcDrops[npc][0]) {
                if(Misc.random(npcDrops[npc][3]) == 0) { //Drops ALWAYS item
                    Item(c, npcDrops[npc][1], npcDrops[npc][2]);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was making a simple class for a small project and decided to just
I'm making a small game in which the Main class holds all the objects
I'm making a small project to learn Django, and i'm having some problems trying
I am making a small game in flash, I would like to track scores
In C# WinForms whenever making a small game here or there, I would write
I am making a small website as my first project. I have finalized to
I'm making a small Android application for a class where I find cancer-related events
Making a small WCF test program which is based on a Store that has
I am making a small game. In BattleRecord.h: #ifndef _CHARACTER_H_ #define _CHARACTER_H_ #include Character.h
So I'm working on a small project that involved creating a camera class with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.