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 9260649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:56:49+00:00 2026-06-18T12:56:49+00:00

I’m just starting out on one of my first programming projects in visual studio

  • 0

I’m just starting out on one of my first programming projects in visual studio 2010.

I have an XML file that I have added into the program as an item. It has the following structure:

<lexeme><grapheme>Aalesund</grapheme>    <phoneme>'A:lI2s,Vnd</phoneme></lexeme>

There are 400,000 entries like that and what I would like to do is on a button press have a random lexeme selected from the xml file and then two labels populated with the corresponding grapheme and phoneme.

Could anyone point me in the right direction to begin with please? The tutorials I have found are for loading specific amounts of data, not just one random line and reference an external xml file location, not one that is internal to the project.

Thanks in advance.

Edit: I should say that I mean pseudo-random number. I was hoping to find a rand() function, but can’t seem to?

  • 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-18T12:56:51+00:00Added an answer on June 18, 2026 at 12:56 pm

    There isn’t a direct way of getting a random line from an XML. And relying on line number is dangerous because if the format of the XML were to be changed from:

    <lexeme><grapheme>Aalesund</grapheme>    <phoneme>'A:lI2s,Vnd</phoneme></lexeme>
    

    to:

    <lexeme>
      <grapheme>Aalesund</grapheme>    
      <phoneme>'A:lI2s,Vnd</phoneme>
    </lexeme>
    

    Your randomly generated line number might not line up with a <lexeme> element anymore.

    I think the best way to do it is to get all of the <lexeme> elements in a list and randomly generate a number that is within the range of the list:
    (forgive me, but the code sample is in c#, I don’t trust my VB.Net enough to write my code in VB)

    var lexemeList = xDocument.Descendants("lexeme").ToList();
    var random = new Random();
    
    var randomLexeme = lexemeList[random.Next(0, lexemeList.Count-1)];
    

    randomLexme will then have a pseudo-random <lexeme> element and you can parse it as you need to get the appropriate <grapheme> and <phoneme> elements.

    If you do this though, keep in mind that the .net Random class is pseudo-random and uses the current timestamp as a seed. If you are going to be accessing objects regularly, it would be advisable to make the var random = new Random() variable as class-level field and create it once and just used the Next() method to get the next number, rather than creating a new Random() object whenever you need a random number.

    Here’s a more self contained function in VB.Net:

    Dim rand = New Random()
    Dim myXml = New XDocument()
    
    Function GetRandomLexeme() as XElement
    
        Dim lexemeList = myXml.Descendants("lexeme").ToList()
        Dim randomLexeme = lexemeList(rand .Next(0, lexemeList.Count - 1))
    
        GetRandomLexeme = randomLexeme
    
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a small JavaScript validation script that validates inputs based on Regex. I
In my XML file chapters tag has more chapter tag.i need to display chapters
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I know there's a lot of other questions out there that deal with this
I have a reasonable size flat file database of text documents mostly saved in
I'm parsing an XML file, the creators of it stuck in a bunch social

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.